901. 滑雪

#include<iostream>
using namespace std;

const int N = 310;

int r, c;
int g[N][N];
int f[N][N];
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
 
int check(int x, int y){
   return x >= 0 && y >= 0 && x < r && y < c;
}

int dfs(int x, int y){
    if(!f[x][y]){
        int ans = 0;
        for(int i = 0; i < 4; i ++){
            int a = x + dx[i], b = y + dy[i];
            if(check(a, b) && g[x][y] > g[a][b]) 
                ans = max(ans, dfs(a, b));
        }
        f[x][y] = ans + 1;
    }
    return f[x][y];
}

int main(){
    cin >> r >> c;
    
    for(int i = 0; i < r; i ++)
        for(int j = 0; j < c; j ++)
            cin >> g[i][j];
    
    
    int res = 0;
    
    for(int i = 0; i < r; i ++)
        for(int j = 0; j < c; j ++)
            res = max(res, dfs(i, j));
            
    cout << res;
}
posted @ 2020-09-08 21:32  yys_c  阅读(93)  评论(0)    收藏  举报