Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 87128 | Accepted: 32633 |
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
#include"cstdio" #include"cstring" #include"algorithm" using namespace std; const int MAXN=105; int n,m; int h[MAXN][MAXN]; int dp[MAXN][MAXN]; int dy[4]={0,1,0,-1}; int dx[4]={1,0,-1,0}; int dfs(int y,int x) { if(dp[y][x]) return dp[y][x]; int res=0; for(int i=0;i<4;i++) { int ny=y+dy[i]; int nx=x+dx[i]; if(0<=ny&&ny<n&&0<=nx&&nx<m&&h[y][x]>h[ny][nx]) res=max(dfs(ny,nx),res); } return dp[y][x]=res+1; } int main() { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&h[i][j]); int ans=0; for(int i=0;i<n;i++) for(int j=0;j<m;j++) ans=max(dfs(i,j),ans); printf("%d\n",ans); return 0; }
原文:http://www.cnblogs.com/program-ccc/p/5185718.html