Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

高手帮忙看看,怎么老是WA,测试数据都对?

Posted by gaoxiao at 2007-04-08 22:34:02 on Problem 1088
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator