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 woshiniya at 2007-03-30 15:10:51 on Problem 1088
#include <iostream>
using namespace std;

int index[100][100], num[100][100], ans, row, col;
void Dfs(int, int, int);

void main() {
	int tmp, i, j;
	scanf("%d%d", &row, &col);
	for(i = 0; i < row; i++) {
		for(j = 0; j < col; j++)
			scanf("%d", &num[i][j]);
	}
	ans = 1;
	tmp = 1;
	memset(index, 0, sizeof(index));
	for(i = 0; i < row ; i++) {
		for(j = 0; j < col; j++) {
			if(index[i][j] == 0) 
				Dfs(i, j, tmp);
		}
	}
	printf("%d\n", ans);
}

void Dfs(int a, int b, int tot) {
	if(tot > index[a][b]) {
		index[a][b] = tot;
		if(tot > ans)
			ans = tot;
		if(a > 0) {
			if(num[a-1][b] < num[a][b])
				Dfs(a-1, b, tot+1);
		}
		if(b > 0) {
			if(num[a][b-1] < num[a][b])
				Dfs(a, b-1, tot+1);
		}
		if(a < row-1) {
			if(num[a+1][b] < num[a][b])
				Dfs(a+1, b, tot+1);
		
		}
		if(b < col-1) {
			if(num[a][b+1] < num[a][b]) 
				Dfs(a, b+1, tot+1);
		}
	}
}
			

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