标签:poj
| Time Limit: 1000MS | Memory Limit: 65536K | |
Description
1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
Input
Output
Sample Input
5 5 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
Sample Output
25
Source
#include<iostream>
#include<cstdio>
#include<cstring>
const int offx[4]={1,0,-1, 0};
const int offy[4]={0,1, 0,-1},maxn=110;
int r,c,dp[maxn][maxn],height[maxn][maxn];
int DP(int x,int y){
int ret=0;
if(dp[x][y]!=-1) return dp[x][y];
for(int i=0;i<4;i++){
int newx=x+offx[i],newy=y+offy[i];
if(newx<0||newy<0||newx>=r||newy>=c) continue;
if(height[x][y]<=height[newx][newy]) continue;
if(DP(newx,newy)>ret) ret=DP(newx,newy);
}
return dp[x][y]=ret+1;
}
void solve(){
int ans=0;
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
if(DP(i,j)>ans) ans=DP(i,j);
}
}
printf("%d\n",ans);
}
int main(){
while(scanf("%d%d",&r,&c)!=EOF){
memset(dp,-1,sizeof(dp));
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
scanf("%d",&height[i][j]);
}
}
solve();
}
return 0;
}
标签:poj
原文地址:http://blog.csdn.net/hush_lei/article/details/38755639