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 |
高手帮忙看看,怎么老是WA,测试数据都对?#include<iostream> #include<string.h> using namespace std; int h[100][100],visit[100][100],len[100][100]; int d[4][2]={0,1,0,-1,1,0,-1,0}; void dfs(int u,int v,int r,int c) { int i,a,b; visit[u][v]=1; for(i=0;i<4;i++) { if(!(u+d[i][0]>=0 && u+d[i][0]<c && v+d[i][1]>=0 && v+d[i][1]<r)) continue; a=u+d[i][0]; b=v+d[i][1]; if(h[a][b]<h[u][v]) { if(visit[a][b]==0) { visit[a][b]=1; dfs(a,b,r,c); len[u][v]=len[u][v]>(len[a][b]+1)?len[u][v]:len[a][b]+1; } else { len[u][v]=len[u][v]>(len[a][b]+1)?len[u][v]:len[a][b]+1; } } } } int main() { int r,c; int i,j; int max=0; memset(visit,0,sizeof(visit)); for(i=0;i<100;i++) for(j=0;j<100;j++) len[i][j]=1; cin>>r>>c; for(i=0;i<r;i++) for(j=0;j<c;j++) cin>>h[i][j]; for(i=0;i<r;i++) for(j=0;j<c;j++) { if(visit[i][j]==0) dfs(i,j,r,c); max=len[i][j]>max?len[i][j]:max; } cout<<max<<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