poj 1088 滑雪
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int mapp[111][111]; int uu[111][111]; struct abc{ int x, y, hh; } node[111 * 111]; bool cmp(const abc&a, const abc&b) { return a.hh > b.hh; } int dir[4][2] = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } }; int main() { int m, n, i, j, k; while (~scanf("%d%d", &n, &m)) { int tot = 0; for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) scanf("%d", &mapp[i][j]); for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { node[tot].x = i; node[tot].y = j; node[tot].hh = mapp[i][j]; tot++; } } sort(node, node + tot, cmp); memset(uu, 0, sizeof(uu)); for (i = 0; i < tot; i++) { for (k = 0; k < 4; k++) { int xx = node[i].x + dir[k][0]; int yy = node[i].y + dir[k][1]; if (xx >= 1 && xx <= n&&yy >= 1 && yy <= m) if (uu[node[i].x][node[i].y] + 1>uu[xx][yy]) if (mapp[node[i].x][node[i].y]>mapp[xx][yy]) uu[xx][yy] = uu[node[i].x][node[i].y] + 1; } } int anss = -1; for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) if (uu[i][j] > anss) anss = uu[i][j]; printf("%d\n", anss + 1); } return 0; }