标签:
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<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<cstdlib> 6 #include<algorithm> 7 #include<vector> 8 using namespace std; 9 const int MAXN = 101; 10 int n,m; 11 int ans; 12 int a[MAXN][MAXN],f[MAXN][MAXN]; 13 int mov[4][2]={{0,1},{1,0},{-1,0},{0,-1}}; 14 15 inline int dp(int x,int y){ 16 if(f[x][y]!=0) return f[x][y]; 17 int nowD=0; 18 for(int i=0;i<4;i++) { 19 int nowx=x+mov[i][0],nowy=mov[i][1]+y; 20 if(nowx>0 && nowy>0 && nowx<=n && nowy<=m && a[nowx][nowy]<a[x][y]) { 21 int Max=dp(nowx,nowy); 22 if(Max>nowD) nowD=Max; 23 } 24 } 25 f[x][y]=nowD+1; 26 return nowD+1; 27 } 28 29 int main() 30 { 31 scanf("%d%d",&n,&m); 32 for(int i=1;i<=n;i++) 33 for(int j=1;j<=m;j++) 34 scanf("%d",&a[i][j]); 35 36 for(int i=1;i<=n;i++) 37 for(int j=1;j<=m;j++){ 38 f[i][j]=dp(i,j); 39 if(f[i][j]>ans) ans=f[i][j]; 40 } 41 42 printf("%d",ans); 43 44 return 0; 45 }
标签:
原文地址:http://www.cnblogs.com/ljh2000-jump/p/5568760.html