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<cstdio> using namespace std; int map[105][105]; int dist[105][105]; bool judge[105][105]; int max; int r,c; int d_max(int a,int b) { return a>b?a:b; } int dfs(int x,int y) { bool flag; flag=false; if(x>0&&map[x][y]>map[x-1][y]) { if(judge[x-1][y]) dist[x][y]=d_max(dfs(x-1,y)+1,dist[x][y]); else dist[x][y]=d_max(dist[x][y],dist[x-1][y]+1); flag=true; } if(y<c-1&&map[x][y]>map[x][y+1]) { if(judge[x][y+1]) dist[x][y]=d_max(dfs(x,y+1)+1,dist[x][y]); else dist[x][y]=d_max(dist[x][y],dist[x][y+1]+1); flag=true; } if(x<r-1&&map[x][y]>map[x+1][y]) { if(judge[x+1][y]) dist[x][y]=d_max(dfs(x+1,y)+1,dist[x][y]); else dist[x][y]=d_max(dist[x][y],dist[x+1][y]+1); flag=true; } if(y>0&&map[x][y]>map[x][y-1]) { if(judge[x][y-1]) dist[x][y]=d_max(dfs(x,y-1)+1,dist[x][y]); else dist[x][y]=d_max(dist[x][y],dist[x][y-1]+1); flag=true; } if(!flag) dist[x][y]=1; judge[x][y]=false; if(dist[x][y]>max) max=dist[x][y]; return dist[x][y]; } int main() { int i,j; int h; while(scanf("%d%d",&r,&c)!=EOF) { max=-1; for(i=0; i<r; i++) for(j=0; j<c; j++) { dist[i][j]=-1; judge[i][j]=true; scanf("%d",&h); map[i][j]=h; } for(i=0; i<r; i++) for(j=0; j<c; j++) if(judge[i][j]) dfs(i,j); printf("%d\n",max); } return 0; } 。。。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator