80 PTS 玄关求助

P1434 [SHOI2002] 滑雪

ljhtomorrow @ 2023-11-27 17:53:52

#include<bits/stdc++.h>
using namespace std;
const int N=2e2+2;
int dx[5]={0,0,0,1,-1};
int dy[5]={0,1,-1,0,0};
int n,m,a[N][N],s[N][N],cnt;
bool vis[N][N];
int dfs(int x,int y){
    if(s[x][y])return s[x][y];
    s[x][y]=1;
    for(int i=1;i<=4;i++){
        int xx=dx[i]+x;
        int yy=dy[i]+y;
        if(xx>0&&yy>0&&xx<=n&&yy<=m&&a[x][y]>a[xx][yy]){
            dfs(xx,yy);
            s[x][y]=max(s[x][y],s[xx][yy]+1);
        }
    }
    return s[x][y];
}
int main() {
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            cin>>a[i][j];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cnt=max(cnt,dfs(i,j));
    cout<<cnt;
    return 0;
}

WA on #2,#6


by XuYueming @ 2023-11-27 18:05:27

#include<bits/stdc++.h>
using namespace std;
const int N=2e2+2;
int dx[5]={0,0,0,1,-1};
int dy[5]={0,1,-1,0,0};
int n,m,a[N][N],s[N][N],cnt;
bool vis[N][N];
int dfs(int x,int y){
    if(s[x][y])return s[x][y];
    s[x][y]=1;
    for(int i=1;i<=4;i++){
        int xx=dx[i]+x;
        int yy=dy[i]+y;
        if(xx>0&&yy>0&&xx<=n&&yy<=m&&a[x][y]>a[xx][yy]){
            dfs(xx,yy);
            s[x][y]=max(s[x][y],s[xx][yy]+1);
        }
    }
    return s[x][y];
}
int main() {
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)  // here
            cin>>a[i][j];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cnt=max(cnt,dfs(i,j));
    cout<<cnt;
    return 0;
}

by XuYueming @ 2023-11-27 18:05:54

@ljhtomorrow 输入的循环写错了


by ljhtomorrow @ 2023-11-27 18:07:27

@XuYueming 歇歇我没脑汁awa


by 2022_37_yzyUUU @ 2023-11-28 17:41:14

@ljhtomorrow 6


by ljhtomorrow @ 2023-11-28 18:00:31

@2022_37_yzyUU sss


|