50分,第二个RE,4WA

P1434 [SHOI2002] 滑雪

an_xi @ 2020-11-03 22:28:46

#include<bits/stdc++.h>
using namespace std;
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
int r,c;
int i,j;
int a[105][105],b[105][105];
int find(int x,int y){
    if(b[x][y]) return b[x][y];
    b[x][y]=1;
    for(i=0;i<4;i++){
        int xx=dx[i]+x;
        int yy=dy[i]+y;
        if(xx>0&&yy>0&&xx<=r&&yy<=c&&a[x][y]>a[xx][yy]){
            find(xx,yy);
            b[x][y]=max(b[x][y],b[xx][yy]+1);
        }
    }
    return b[x][y];
}
int main(){
    cin>>r>>c;
    for(i=1;i<=r;i++){
        for(j=1;j<=c;j++){
            scanf("%d",&a[i][j]);
        }
    }
    int ans;
    for(i=1;i<=r;i++){
        for(j=1;j<=c;j++){
            ans=max(ans,find(i,j));
        }
    }
    cout<<ans;
    return 0;
}

|