P1434求捞
  • 板块灌水区
  • 楼主SpriteQAQ
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/8/20 16:01
  • 上次更新2024/8/20 17:37:44
查看原帖
P1434求捞
1246673
SpriteQAQ楼主2024/8/20 16:01

门

#include <bits/stdc++.h>
using namespace std;
int n, m, a[105][105], ans, s[105][105];
int dx[5] = {0, 0, 1, -1};
int dy[5] = {1, -1, 0, 0};
//s[i][j]表示在i行j列能划到的最长距离
int dfs(int x, int y){
    if(s[x][y] != 0) return s[x][y]; //记搜
    s[x][y] = 1;
    for (int i = 0; i < 4; i++){
        int xx = dx[i] + x, yy = dy[i] + y;//kkk式取名法
        if(xx < 1 || yy < 1 || xx > n || yy > m){
            if(a[x][y] <= a[xx][yy]){
                continue;
            }
        }
        dfs(xx, yy);
        s[x][y] = max(s[x][y], s[xx][yy] + 1);//记搜
    }
    return s[x][y];
}
int main(){
    cin >> n >> m;
    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++){
            ans = max(ans, dfs(i, j));
        }
    }
    cout << ans;
    return 0;
}
2024/8/20 16:01
加载中...