交了几发都是2,10WA/RE

P1434 [SHOI2002] 滑雪

zexuan_k @ 2020-03-22 14:16:02

如题,看了一下题解,没有找出错误,求助。

#include <bits/stdc++.h>

using namespace std;

const int N = 210;

struct node {
    int x, y, ht;
} a[N];

bool cmp (node a, node b) {
    return a.ht < b.ht;
}

int f[N][N], h[N][N], n, m, cnt = 0;

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            scanf("%d", &h[i][j]);
            a[++cnt].ht =  h[i][j];
            a[cnt].x = i;
            a[cnt].y = j;
            f[i][j] = 1;
        }
    }
    sort(a + 1, a + cnt + 1, cmp);
    int ans = 0;
    for (int i = 1; i <= cnt; ++i) {
        int d = a[i].ht;
        int xi = a[i].x, yi = a[i].y;
        if (d > h[xi - 1][yi] && xi >= 1) f[xi][yi] = max(f[xi][yi], f[xi - 1][yi] + 1);
        if (d > h[xi + 1][yi] && xi <= n) f[xi][yi] = max(f[xi][yi], f[xi + 1][yi] + 1);
        if (d > h[xi][yi - 1] && yi >= 1) f[xi][yi] = max(f[xi][yi], f[xi][yi - 1] + 1);
        if (d > h[xi][yi + 1] && yi <= m) f[xi][yi] = max(f[xi][yi], f[xi][yi + 1] + 1);
        ans = max(ans, f[xi][yi]);
    }
    printf("%d", ans);
    return 0;
}

|