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 |
一次AC 简单的dfs#include<iostream> using namespace std; struct NODE{ int i; int j; }; NODE node[4]={{-1,0},{0,1},{1,0},{0,-1}}; int f[102][102],num[102][102]; int dfs(int i,int j){ for(int t=0;t<4;t++){ if(f[i][j]>f[i+node[t].i][j+node[t].j]){ if(num[i+node[t].i][j+node[t].j]==0)num[i+node[t].i][j+node[t].j]=dfs(i+node[t].i,j+node[t].j); num[i][j]=(num[i+node[t].i][j+node[t].j]+1>num[i][j])?num[i+node[t].i][j+node[t].j]+1:num[i][j]; } } if(num[i][j]==0)num[i][j]=1; return num[i][j]; } int main(){ int r,c,i,j; while(scanf("%d%d",&r,&c)!=EOF){ for(i=0;i<=r+1;i++) for(j=0;j<=c+1;j++){ if(i==0||j==0||i==r+1||j==c+1)f[i][j]=10001; else { scanf("%d",&f[i][j]); num[i][j]=0; } } int max=0; for(i=1;i<=r;i++) for(j=1;j<=c;j++){ if(num[i][j]==0)num[i][j]=dfs(i,j); if(max<num[i][j])max=num[i][j]; } cout<<max; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator