int right(int n)
{
if(n>0)
{
n--;
top_lim ++;
cout<<"R";
right_lim--;
if(right_lim < size)
return(right(n-1));
i开发者_开发问答f(top_lim>0)
--> return(up(n - 1));
}
else
{
return 0;
}
}
int up(int n)
{
if(n>1)
{
n--;
top_lim --;
cout<<"U";
if(right_lim < size)
return(right(n-1));
if(top_lim > 0 )
return(up(n-1));
}
else
{
return 0;
}
}
error: [17] 'up' was not declared in this scope|--> indicates error in code ..
Description of problem:
The problem is to find all the possible number of paths in a n*n grid in the portion below the diagonal starting from (0,0) to (n,n) I basically call the right function first in the main function and then it should print me all paths.
Is there a workaround for this?
Add a forward declaration at the top of your code:
int up(int);
(Make sure to compile that code with full optimizations! :-) )
精彩评论