比赛 初一开训小练习 评测结果 AAAAAAAATA
题目名称 最长滑坡 最终得分 90
用户昵称 贺元莘 运行时间 1.617 s
代码语言 C++ 内存使用 4.17 MiB
提交时间 2026-03-10 20:34:26
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
int b=1;
int a[505][505];
    int maxx=1;
int r,c;
void dfs(int i,int j){
    for(int k=0;k<=3;k++){
        int ai=dx[k]+i;
        int aj=dy[k]+j;
        if (ai >= 1 && ai <= r && aj >= 1 && aj <= c && a[i][j] > a[ai][aj]) {
            b++;
            dfs(ai,aj);
            b--;
        }
    }
    maxx=max(maxx,b);
    return;   
}
int main(){
    freopen("shunzhi.in","r",stdin);
    freopen("shunzhi.out","w",stdout);
    cin >> r >> c;
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            cin >> a[i][j];            
        }
    }
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            dfs(i,j);
        }
    }
    cout << maxx;

    
    return 0;
}