ACM PUK 1088 滑雪 http://acm.pku.edu.cn/JudgeOnline/problem?id=1088
人家都说这是一道动态规划题,而我认为这不过是一道广搜题,递归就完全可以解决,而且还不需要用队列,代码很简单也很容易懂,说太多没用,大家都知道,我的代码:
#include <iostream>
using namespace std;
int slope[100][100];
int changdu[100][100];
int R , C ;
int fuc (int i,int j)
{
int max = 0 ;
if ( changdu[i][j] > 0 ) return changdu[i][j];
if ( i-1>=0)
{
if ( slope[i-1][j] > slope[i][j] )
{
if ( max < fuc(i-1 , j))
max = fuc(i-1,j);
}
}
if ( i+1 < R)
{
if ( slope[i+1][j] > slope[i][j] )
{
if ( max < fuc(i+1 , j))
max = fuc(i+1,j);
}
}
if ( j-1>=0)
{
if ( slope[i][j-1] > slope[i][j] )
{
if ( max < fuc(i , j-1))
max = fuc(i ,j-1);
}
}
if ( j+1 < R)
{
if ( slope[i][j+1] > slope[i][j] )
{
if ( max < fuc(i , j+1))
max = fuc(i,j+1);
}
}
return changdu[i][j] = max+1;
}
int main ()
{
memset(slope, 0, sizeof(int));
cin >>R>>C;
for (int i=0; i<R; i++)
for (int j=0; j<C; j++)
{
cin >> slope[i][j];
changdu[0][0];
}
for (int a=0; a<R; a++)
for (int b=0; b<C; b++)
{
fuc(a,b);
}
int temp=0;
for (int A=0; A<R; A++)
for (int B=0; B<C; B++)
{
if (temp<changdu[A][B])
temp=changdu[A][B];
}
cout<<temp<<endl;
return 0;
}
浙公网安备 33010602011771号