标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 90368 | Accepted: 34028 |
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
1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 #include<cstdio> 5 #include<queue> 6 #define ll long long 7 #define mod 1e9+7 8 #define PI acos(-1.0) 9 #define bug(x) printf("%%%%%%%%%%%%%",x); 10 #define inf 1e8 11 using namespace std; 12 int r,c; 13 int mp[105][105]; 14 int dp[105][105]; 15 int dis[4][3]={{1,0},{0,1},{0,-1},{-1,0}}; 16 int ans=0; 17 int dfs(int x,int y) 18 { 19 if(dp[x][y]) 20 return dp[x][y]; 21 int zha=0; 22 for(int i=0;i<=3;i++) 23 { 24 int xx=x+dis[i][0]; 25 int yy=y+dis[i][1]; 26 if(xx>0&&xx<=r&&yy>0&&yy<=c) 27 { 28 if(mp[x][y]>mp[xx][yy]) 29 zha=max(zha,dfs(xx,yy)); 30 } 31 } 32 dp[x][y]=zha+1; 33 return dp[x][y]; 34 } 35 int main() 36 { 37 while(scanf("%d %d",&r,&c)!=EOF) 38 { 39 ans=0; 40 memset(mp,0,sizeof(mp)); 41 memset(dp,0,sizeof(dp)); 42 for(int i=1;i<=r;i++) 43 { 44 for(int j=1;j<=c;j++) 45 scanf("%d",&mp[i][j]); 46 } 47 for(int i=1;i<=r;i++) 48 { 49 for(int j=1;j<=c;j++) 50 { 51 int gg=dfs(i,j); 52 ans=max(ans,gg); 53 } 54 } 55 printf("%d\n",ans); 56 } 57 return 0; 58 }
标签:
原文地址:http://www.cnblogs.com/hsd-/p/5676836.html