分析:记忆化搜索DP。dp[i][j]表示从上下左右四点中滑到该点的最长路程,则dp[i][j]=max(dp[i-1][j],dp[i][j-1],dp[i+1][j],dp[i][j+1])+1;
source code:
#include<cstdio>
#include<cstring>
#define INF 0x3f3f3f3f
#define M 105
int X[]={-1,1,0,0},Y[]={0,0,-1,1};
int map[M][M],len[M][M];
int r,c;
bool Ok(int i,int j){
if(i>0&&i<=r&&j>0&&j<=c) return true;
return false;
}
int DFS(int x,int y){
int temp,k;
if(len[x][y]>0) return len[x][y];
for(k=0;k<4;k++){
if(Ok(x+X[k],y+Y[k])&&(map[x+X[k]][y+Y[k]]>map[x][y])){
temp=DFS(x+X[k],y+Y[k])+1;
if(temp>len[x][y]) len[x][y]=temp;
}
}
return len[x][y];
}
int main()
{
int i,j,ans,temp;
while(scanf("%d %d",&r,&c)==2){
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
scanf("%d",&map[i][j]);
ans=-INF;
memset(len,0,sizeof(len));
for(i=1;i<=r;i++){
for(j=1;j<=c;j++){
temp=DFS(i,j);
if(ans<temp) ans=temp;
}
}
printf("%d\n",ans+1);
}
return 0;
}