70pts

P1434 [SHOI2002] 滑雪

ytr2010 @ 2023-09-02 15:25:13

#include<bits/stdc++.h>
using namespace std;
int mp[105][105],vis[101][101],n,m,ans=0;
int dx[]={-1,1,0,0}, dy[]={0,0,-1,1};
int dfs(int x,int y,int maxfrom)
{
    int sum=0;
    if(mp[x][y]>=maxfrom) return 0;
    if(mp[x][y]==1) return 1; 
    for(int i=0;i<4;i++)
    {
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx>n||nx<=0||ny>m||ny<=0) continue;
        if(vis[nx][ny]==0)
        {
            vis[nx][ny]=1;
            sum=max(sum,dfs(nx,ny,mp[x][y]));
            vis[nx][ny]=0;
        }
    }
    return sum+1;
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>mp[i][j];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            vis[i][j]=1;                       
            ans=max(ans,dfs(i,j,0x7f));
            vis[i][j]=0;  
        } 
    cout<<ans;
    return 0;
}

|