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

为什么 深搜就错了?

Posted by sailors at 2007-08-30 15:03:16 on Problem 1088
// pk1088.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#define MAXN 110
#define MAXSHORT 30000
const int dr[4]={0,1,0,-1};
const int dc[4]={-1,0,1,0};
short map[MAXN][MAXN];
char best[MAXN][MAXN];
void dfs(int r,int c){
	int i,rr,cc;
	best[r][c]=1;
	for(i=0;i<4;i++){
		rr=r+dr[i];
		cc=c+dc[i];
		if(map[rr][cc]>=map[r][c])
			continue;
		if(best[rr][cc]==1)
			dfs(rr,cc);
		if(best[rr][cc]+1>best[r][c])
			best[r][c]=best[rr][cc]+1;
	}
}
int main(int argc, char* argv[])
{
	int n,m,i,j,ans;
	while(scanf("%d%d",&n,&m)!=EOF){
		for(i=1;i<=n;i++)
			for(j=1;j<=m;j++)
				scanf("%d",&map[i][j]);
		for(i=0;i<=n+1;i++)
			map[i][0]=map[i][m+1]=MAXSHORT;
		for(i=1;i<=m;i++)
			map[0][i]=map[n+1][i]=MAXSHORT;
		for(i=1;i<=n;i++)
			for(j=1;j<=m;j++)
				best[i][j]=1;
		ans=0;
		for(i=1;i<=n;i++)
			for(j=1;j<=m;j++)
				if(best[i][j]==1){
					dfs(i,j);
					if(best[i][j]>ans)
						ans=best[i][j];
				}
			//	i++;
		printf("%d\n",ans);
	}
	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