标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 89168 | Accepted: 33474 |
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<cstdio> #include<iostream> using namespace std; #define N 101 int f[N][N]; int a[N][N]; int m,n; int get(int i,int j){ if(f[i][j]>1) return f[i][j]; int maxn=1,h; if(a[i][j]>a[i][j-1]&&j-1>=0) h=get(i,j-1)+1,maxn=max(maxn,h); if(a[i][j]>a[i][j+1]&&j+1<m) h=get(i,j+1)+1,maxn=max(maxn,h); if(a[i][j]>a[i-1][j]&&i-1>=0) h=get(i-1,j)+1,maxn=max(maxn,h); if(a[i][j]>a[i+1][j]&&i+1<n) h=get(i+1,j)+1,maxn=max(maxn,h); return maxn; } int main() { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&a[i][j]),f[i][j]=1; int ans=0; for(int i=0;i<n;i++) for(int j=0;j<m;j++) f[i][j]=get(i,j),ans=max(ans,f[i][j]); printf("%d\n",ans); return 0; }
#include<cstdio> #include<iostream> #define N 101 using namespace std; int dx[5]={0,-1,0,1,0}, dy[5]={0,0,1,0,-1}; int a[N][N],f[N][N],l,r; int get(int x,int y){ if(f[x][y]) return f[x][y]; int tmp,t=1; for(int i=1;i<=4;i++){ int nx=x+dx[i]; int ny=y+dy[i]; if(nx>0&&nx<=l&&ny>0&&ny<=r&&a[x][y]<a[nx][ny]){ tmp=get(nx,ny)+1; t=max(tmp,t); } } return f[x][y]=t; } int main(){ int t,ans=0; scanf("%d%d",&l,&r); for(int i=1;i<=l;i++) for(int j=1;j<=r;j++) scanf("%d",&a[i][j]); for(int i=1;i<=l;i++) for(int j=1;j<=r;j++) f[i][j]=get(i,j),ans=max(ans,f[i][j]); printf("%d\n",ans); return 0; }
标签:
原文地址:http://www.cnblogs.com/shenben/p/5495302.html