POJ 1008 深度优先、记忆搜索
2013-05-15 22:10
253 查看
http://blog.sina.com.cn/s/blog_7025794a01014pps.html
#include <iostream> #include <string> using namespace std; const int MAXN = 100; int r, c; int h[MAXN+1][MAXN+1]; int f[MAXN+1][MAXN+1]; bool Valid(int x, int y) { return x >= 1 && x <= r && y >= 1 && y <= c; } int F(int i, int j) { if (f[i][j] != 0) { return f[i][j]; } int d; const int dir[][2] = {{0, ‐1}, {‐1, 0}, {0, 1}, {1, 0}}; for (d = 0; d < 4; d ++) { int x = i + dir[d][0], y = j + dir[d][1]; if (Valid(x, y) && h[x][y] < h[i][j] && F(x, y) > f[i][j]) { f[i][j] = F(x, y); } } return ++f[i][j]; } int main() { int i, j; cin >> r >> c; for (i = 1; i <= r; i ++) { for (j = 1; j <= c; j ++) { cin >> h[i][j]; } } int ans = 0; for (i = 1; i <= r; i ++) { for (j = 1; j <= c; j ++) { if (F(i, j) > ans) { ans = F(i, j); } } } cout << ans << endl; return 0; }
相关文章推荐
- Late Counting (POJ 2386) 深度优先搜索
- poj1312 dfs 深度优先搜索
- POJ 1979 深度优先搜索
- POJ3009 - Curling 2.0 - 深度优先搜索
- 20124330102 【 搜索 -- 深度优先搜索 】 POJ 3414 Pots
- 深度优先搜索dfs(poj 1655)
- POJ 1979 - Red and Black 深度优先搜索
- POJ1562 - Oil Deposits - 深度优先搜索
- 深度优先搜索【POJ 3009】
- 记忆深度优先搜索
- 深度优先搜索 poj 2386
- Hopscotch(poj 3050)深度优先搜索
- 深度优先搜索【POJ 1979】
- 挑战第二章习题 POJ 1974 深度优先搜索
- ACM-POJ 1562 DFS 深度优先搜索
- POJ1321,深度优先搜索
- poj3009之深度优先搜索 dfs解法
- POJ-2386-Lake Counting(深度优先搜索初步!)
- poj1088 滑雪 dp记忆化搜索 dfs深度优先搜索
- POJ1426-Find The Multiple-深度优先搜索BFS