poj 1088 滑雪

#include <iostream>
using namespace std;
int r,c,height[101][101],skate[101][101];
int dp(int i,int j)
{
int up,down,left,right,max=0;
if(i>1&&height[i][j]>height[i-1][j])
{
if(skate[i-1][j]!=0)
down
=skate[i-1][j];
else
down
=dp(i-1,j);
if(max<down)max=down;
}
if(i<r&&height[i][j]>height[i+1][j])
{
if(skate[i+1][j]!=0)
up
=skate[i+1][j];
else
up
=dp(i+1,j);
if(max<up)max=up;
}
if(j>1&&height[i][j]>height[i][j-1])
{
if(skate[i][j-1]!=0)
left
=skate[i][j-1];
else
left
=dp(i,j-1);
if(max<left)max=left;
}
if(j<c&&height[i][j]>height[i][j+1])
{
if(skate[i][j+1]!=0)
right
=skate[i][j+1];
else
right
=dp(i,j+1);
if(max<right)max=right;
}
skate[i][j]
=1+max;
return skate[i][j];
}
int main()
{
int i,j,max=0;
scanf(
"%d%d",&r,&c);
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
scanf(
"%d",&height[i][j]);
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
dp(i,j);
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
if(skate[i][j]>max)
max
=skate[i][j];
printf(
"%d\n",max);
return 0;
}

  

posted on 2011-07-20 22:33  sysu_mjc  阅读(109)  评论(0编辑  收藏  举报

导航