jump it game

i'm making a recursive solution to a jump it game.

0 3 80 56 7 10

i ca either move forward 1 or jump over 1 to thereby move 2. The goal is to get the lowest amount.

I've been thinking of doing the total-move1<total-move2 move to 1

basically have the largest number at the end be the most effcient method. I'm wondering if I'm on the right track, and i dont know how i would go about making something recursive, a for loop maybe? since it does a pretest to see which is lower?
I think pasting a sample code will give us a clearer picture of what you meant
Yea I've never heard of this game before, and have no idea what you're trying to accomplish
to get the lowest amount you go to 3, then over one to 56 then over one to 10.
3+56+10=69=correct way
'
bad way:
3+80+7+10=97

will post sample code tomorrow
wouldn't 3+56+7=66 be a better way? ;P

Or do you have to use the last number?

and i dont know how i would go about making something recursive, a for loop maybe?


For loops are iterative, not recursive.

Recursion means to have a function call itself.

Something like this would be a recursive solution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int BestPath(int pos)
{
  if( /* pos is at the end of the buffer */ )
  {
    return buffer[/*last value*/];
  }
  else
  {
    int one = BestPath(pos+1);
    int two = BestPath(pos+2);

    return min(one,two) + buffer[pos];
  }
}
@Disch : Nice solution. I have a similar problem

http://www.cplusplus.com/forum/general/61287/

Although not recursion... It is something to do with dynamic programming...
you can move 1 slot ahead, or skip over the first slot to the second.
how would i get the position to start at the end of the array and move backwards?
Topic archived. No new replies allowed.