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 |
大家进来看下,算法怎么改进啊? 给下提示啊#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator