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 <stdio.h> int map[101][101]; int max[101][101]; int R,C; const int dir[4][2]={{0,-1},{0,1},{-1,0},{1,0}}; int result=0; int dfs(int x,int y) { int i,m=0,temp; int nx,ny; if(max[x][y]) return max[x][y]; for(i=0;i<4;i++) { nx=x+dir[i][0]; ny=y+dir[i][1]; if(nx<R&&nx>=0&&ny<C&&ny>=0&&map[nx][ny]<=map[x][y]) if((temp=dfs(nx,ny))>m) m=temp; } if(m+1>result) result=m+1; return max[x][y]=m+1; } int main() { int a,b; scanf("%d%d",&R,&C); for(a=0;a<R;a++) for(b=0;b<C;b++) { scanf("%d",&map[a][b]); max[a][b]=0; } for(a=0;a<R;a++) for(b=0;b<C;b++) if(!max[a][b]) dfs(a,b); printf("%d",result); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator