不用DFS求调

P1434 [SHOI2002] 滑雪

TLE_MLE_RE @ 2024-08-03 20:18:31

#include <iostream>
#include <vector>
using namespace std;

const int N = 101;

void f(int r, int c, vector<vector<int>>& h) {
    vector<vector<int>> d(r, vector<int>(c, 1));

    int ml = 1;

    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            if (j && h[i][j] > h[i][j-1]) d[i][j] = d[i][j-1] + 1;
            if (i && h[i][j] > h[i-1][j]) d[i][j] = max(d[i][j], d[i-1][j] + 1);
            ml = max(ml, d[i][j]);
        }
    }

    cout << ml << endl;
}

int main() {
    int r, c;
    cin >> r >> c;
    vector<vector<int>> h(r, vector<int>(c));
    for (int i = 0; i < r; ++i)
        for (int j = 0; j < c; ++j) 
            cin >> h[i][j];
    f(r, c, h);
    return 0;
}

|