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

一次AC 简单的dfs

Posted by 785815369 at 2010-02-11 16:06:03 on Problem 1088
#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:
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