为何会WA,dalao求调

P1434 [SHOI2002] 滑雪

ljkgs6789 @ 2024-01-31 14:07:01

#include<bits/stdc++.h>
using namespace std;
int r,c,a[101][101],vis[101][101],ans=-1;
int tx[6]={0,1,0,-1,0},ty[6]={0,0,1,0,-1};
void dfs(int x,int y,int last,int cnt){
    if(vis[x][y]==1||x<1||x>r||y<1||y>c||a[x][y]>=last){
        return ;
    }
    vis[x][y]=1;
    ans=max(ans,cnt);
    for(int i=1;i<=4;i++){
        dfs(x+tx[i],y+ty[i],a[x][y],cnt+1);
        vis[x][y]=0;
    }
}
int main(){
    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,214748364,1);
        }
    }
    if(ans==-1){
        cout<<1;
    }else{
        cout<<ans;
    }
    return 0;
}

by General0000826 @ 2024-01-31 14:14:22

记忆化呢?


|