Hi guys, I need your help about something in C++. So, very soon I'm going to have a competition in C++ programming in my school and we were just introduced to dynamic programming in our C++ class. However, I was a bit late and missed almost a half of lecture. I do understand what dynamic programming basically is, solving a bigger problem by solving smaller subproblems that have the same properties as the big problem... Now, the professor is very good and I somehow was able to understand the algorithm, but I have no idea how to implement it in C++ when trying to solve some exercises.
So, here's one task I'd like you to help me with. It's one of the easiest ones, but I'm sure that if I understand how to implement the algorithm here, I'll know how to solve bigger problems. The task text is in Croatian however, so I'm going to try and translate it. "One day Marco searched through his grandfather's stuff and found a dusty map of buried golden treasures (the grandfather was a pirate). On the map there is a geographical web that splits the map on N rows and M columns. Marco's ship is in the upper left corner of the web (or map). He wanted to collect all the treasures, but his ship is partly wrecked and can move only right or down on the map. Marco wants us to write a program that is going to allow him to collect as many treasures as possible by moving ONLY up or down."
INPUT DATA:
- natural number N (1 <= N <= 1000) and M (1 <= M <= 1000) --> numbers of rows and columns on the map
- next N rows contain the content of the map, where '.' means no treasure and 'D' means there is a treasure on those coordinates
OUTPUT DATA:
- maximum number of treasures that can be collected by moving ONLY up or down
EXAMPLE OF TEST DATA:
Standard Input
4 5
. . D . .
. D . . .
D . . . .
. . D . D
Standard Output
3
Also, don't use any libraries except <iostream> or <cstdio> please. :) Thank you very much!!
> moving ONLY up or down
that would restring him to only one column, given that the initial position is fixed (upper left) then you only care for the first column and the rest is noise.
maybe it was `right' or `down'.
edit:
> but his ship is partly wrecked and can move only right or down on the map.
> collect as many treasures as possible by moving ONLY up or down.
¿which is it?
> but I have no idea how to implement it in C++
If the problem is the implementation, then provide pseudocode and I would translate it for you.
Thank you so much for help everyone, today I asked my professor about the topic and he explained it to me very well. I managed to solve the task both iteratively and recursively using dynamic programming with memoization. :) Problem solved :D