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 |
简单题,我也贴一下代码#include <iostream> #include <cstdio> using namespace std; const int maxn = 110; int gra[maxn][maxn]; int record[maxn][maxn]; int R, C; bool inner(int x, int y) { return x>=1&&x<=R&&y>=1&&y<=C; } int getMax(int x, int y) { if(record[x][y]) return record[x][y]; int maxx = 0; if(inner(x+1,y)&&(gra[x+1][y]<gra[x][y])) maxx = max(maxx, getMax(x+1,y)); if(inner(x-1,y)&&(gra[x-1][y]<gra[x][y])) maxx = max(maxx, getMax(x-1,y)); if(inner(x,y+1)&&(gra[x][y+1]<gra[x][y])) maxx = max(maxx, getMax(x,y+1)); if(inner(x,y-1)&&(gra[x][y-1]<gra[x][y])) maxx = max(maxx, getMax(x,y-1)); return record[x][y] = 1 + maxx; } int main() { while(scanf("%d%d",&R,&C)!=EOF) { for(int i=1;i<=R;i++) { for(int j=1;j<=C;j++) { scanf("%d",&gra[i][j]); record[i][j] = 0; } } int res = 0; for(int i=1;i<=R;i++) { for(int j=1;j<=C;j++) { res = max(res, getMax(i,j)); } } cout<<res<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator