I'm working on this problem that has n positive integers in a row except for the first column, which always contains zero, these numbers represent the cost to enter each column. I'm supposed to get to the end of the board with the path that costs the least. I can either jump 1 or 2 spaces at a time.
So say the board was:
0 3 80 6 57 10
then I would chose; 3, 6 and 10 for a cost of 19. I 'm just having troubles on how the heck I'm supposed to make this a recursive problem. I'm a second year programmer and this is the first time I've come to one of these sites to ask for help because I usually like to figure it out on my own but I just can't seem to think of what I'm doing wrong.
Here is what I have so far:
int jumpIt( int board[], int pos )
{
int value;
if( board[pos+1] < board[pos+2] )
{
value = board[pos+1];
return value;
}
else
{
pos = pos+1;
jumpIt( board, pos );
}
}
Any help on this would be great, hell even an algorithm to get me off on the right foot would be very appreciated.
Thanks,
Scott