题解 | #滑雪#

滑雪

https://www.nowcoder.com/practice/36d613e0d7c84a9ba3af3ab0047a35e0

#include <iostream>
#include<cstring>

using namespace std;

int n, m;
const int N = 110;
int h[N][N];
int f[N][N];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

int df(int x, int y){
    int &v = f[x][y];
    if(v != -1) return v;
    v = 1;
    for(int i = 0; i < 4; i ++){
        int a = x + dx[i], b = y + dy[i];
        if(a >= 1 && a <= n && b >= 1 && b <= m && h[x][y] > h[a][b])
            v = max(v, df(a, b) + 1);
    }
    return v;
}
int main() {
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
            cin >> h[i][j];

    memset(f, -1, sizeof f);
    int res = 0;
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
            res = max(res, df(i, j));
    cout << res << endl;
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务