/**
* JumpGame
*/
#define N 7
int gameBoard[N][N]={
{2,5,1,6,1,4,1},
{6,1,1,2,2,9,3},
{7,2,3,2,1,3,1},
{1,1,3,1,7,1,2},
{4,1,2,3,4,1,2},
{3,3,1,2,3,4,1},
{1,5,2,9,4,7,-1}
};
//int gameBoard[N][N]={
// {1,1,1,1,1,1,1},
// {1,1,1,1,1,1,1},
// {1,1,1,1,1,1,1},
// {1,1,1,1,1,1,1},
// {1,1,1,1,1,1,1},
// {1,1,1,1,1,1,2},
// {1,1,1,1,1,2,-1},
//};
int n=0;
int footStep[N][N];
bool jumpGame(int x,int y){
n++;
//basis
if(x>=N || y>=N){ return false;}
if(x== N -1 && y==N-1){return true;}
if(footStep[x][y]!=-1){ return footStep[x][y];}
footStep[x][y] = jumpGame(x+gameBoard[x][y],y) || jumpGame(x,y+gameBoard[x][y]);
return footStep[x][y];
}
int main(){
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
footStep[i][j]=-1;
}
}
if(jumpGame(0,0)){
printf("Reached a goal.
");
}else{
printf("Not reached a goal.
");
}
printf("Function called %d times
",n);
}