80分的代码,#2#6错误

P1434 [SHOI2002] 滑雪

hycymc @ 2023-10-20 20:28:05

#include <iostream>
using namespace std;
int a[528][528], b[528][528], n, m, sum;
int k(int i, int j) {
    if (b[i][j])return b[i][j];
    b[i][j] = 1;
    if (i + 1 <= n && a[i][j] > a[i + 1][j]) {
        k(i + 1, j);
        b[i][j] = max(b[i][j], b[i + 1][j] + 1);
    }
    if (j + 1 <= n && a[i][j] > a[i][j + 1]) {
        k(i, j + 1);
        b[i][j] = max(b[i][j], b[i][j + 1] + 1);
    }
    if (i - 1 > 0 && a[i][j] > a[i - 1][j]) {
        k(i - 1, j);
        b[i][j] = max(b[i][j], b[i - 1][j] + 1);
    }
    if (j - 1 > 0 && a[i][j] > a[i][j - 1]) {
        k(i, j - 1);
        b[i][j] = max(b[i][j], b[i][j - 1] + 1);
    }
    return b[i][j];
}
int main() {
    cin >> m >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            sum = max(sum, k(i, j));
        }
    }
    cout << sum ;
    return 0;
}

by DZDdzd @ 2023-10-20 20:41:13

把输入里的n,m的位置换一下

cin >> n >> m;


by hycymc @ 2023-10-20 21:20:26

这......就对了!?我不信 AC了,膜拜大佬!!!明天RP++


|