标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 83899 | Accepted: 31413 |
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<stdio.h> #include<string.h> int dp[110][110]; int a[110][110]; int max(int a,int b){ return a>b?a:b; } int n,m; int s[4][2]={1,0,0,1,-1,0,0,-1}; int dfs(int i,int j){ if(dp[i][j]) return dp[i][j]; for(int k=0;k<4;++k){ if(i+s[k][0]>0&&i+s[k][0]<=n&&j+s[k][1]>0&&j+s[k][1]<=m) if(a[i][j]>a[i+s[k][0]][j+s[k][1]]){ dp[i][j]=max(dp[i][j],dfs(i+s[k][0],j+s[k][1])+1); } } return dp[i][j]; } int main(){ while(~scanf("%d%d",&n,&m)){ memset(dp,0,sizeof(dp)); memset(a,0,sizeof(a)); int i,j,res=0; for(i=1;i<=n;++i){ for(j=1;j<=m;++j){ scanf("%d",&a[i][j]); } } for(i=1;i<=n;++i){ for(j=1;j<=m;++j){ res=max(res,dfs(i,j)); } } printf("%d\n",res+1); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/qq_18062811/article/details/47446299