Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
下标从1开始可以省不少事,贴个代码,有需要的可以看一下哈//只要开始时下表从1开始就可以省不少事 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> using namespace std; int n,m; int dp[110][110]; int a[110][110]; int dfs(int x,int y) { if(dp[x][y]!=0) return dp[x][y]; int maxn=0; if(x==0 || x==n+1 || y==0 || y==m+1) return 0; if(a[x-1][y]<a[x][y]) maxn=max(maxn,dfs(x-1,y)); if(a[x+1][y]<a[x][y]) maxn=max(maxn,dfs(x+1,y)); if(a[x][y-1]<a[x][y]) maxn=max(maxn,dfs(x,y-1)); if(a[x][y+1]<a[x][y]) maxn=max(maxn,dfs(x,y+1)); dp[x][y]=maxn+1; return maxn+1; } int main() { while(cin>>n>>m) { memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j]; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) dfs(i,j); int ans=-1; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(dp[i][j]>ans) ans=dp[i][j]; cout<<ans<<endl; } return 0; } /* 3 3 3 2 1 5 6 8 7 4 10 */ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator