求助dalao为什么只有50分??

P1434 [SHOI2002] 滑雪

minkite @ 2018-10-17 22:17:51

#include<bits/stdc++.h>
using namespace std;
int ditu[1000][1000];
int f[1000][1000];
int n,m;
int dfs(int x1,int y1)
{
  if(f[x1][y1]!=1)
    return f[x1][y1];
     int a=0;
   if(x1<=n&&x1>0&&y1<=m&&y1>0&&ditu[x1+1][y1]<ditu[x1][y1])a=max(a,(dfs(x1+1,y1)+1));           
  if(x1<=n&&x1>0&&y1<=m&&y1>0&&ditu[x1-1][y1]<ditu[x1][y1])a=max(a,(dfs(x1-1,y1)+1));    
  if(x1<=n&&x1>0&&y1<=m&&y1>0&&ditu[x1][y1+1]<ditu[x1][y1])a=max(a,(dfs(x1,y1+1)+1));    
if(x1<=n&&x1>0&&y1<=m&&y1>0&&ditu[x1][y1-1]<ditu[x1][y1])a=max(a,(dfs(x1,y1-1)+1));    
f[x1][y1]=max(a,f[x1][y1]);
return a;
}
  int main()
{int maxx=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
      for(int j=1;j<=m;j++)
          {
             cin>>ditu[i][j];
             f[i][j]=1;
             }
             for(int i=1;i<=n;i++)
               for(int j=1;j<=m;j++)
                  maxx=max(maxx,dfs(i,j));
               cout<<maxx;
               }

by HikariForever @ 2018-10-17 22:21:24

@futaba 码风不同所以我并看不懂...所以我只能给你看看我的AC代码了

#include<bits/stdc++.h>
using namespace std;
int f[110][110];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int z[110][110];
int dfs(int x,int y)
{
    int px,py;
    if(f[x][y])return f[x][y];
    f[x][y]=1;
    for(int i=0;i<4;i++)
    {
        px=x+dx[i],py=y+dy[i];
        if(z[px][py]<z[x][y])f[x][y]=max(f[x][y],dfs(px,py)+1);
    }
    return f[x][y];
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<=m+1;i++)
    {
        z[i][0]=z[i][m+1]=1e9;
    }
    for(int i=0;i<=n+1;i++)
    {
        z[0][i]=z[n+1][i]=1e9;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>z[i][j];
        }
    }
    int ans=-1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            ans=max(dfs(i,j),ans);
        }
    }
    cout<<ans<<endl;
    return 0;
}

by Estella @ 2018-10-17 23:02:42

@futaba dfs里int a=1


by minkite @ 2018-10-18 22:32:05

@Rowena

已AC, 谢谢, 可以解释一下吗


by Estella @ 2018-10-21 00:01:57

x1,y1的初始高度要算。不管在哪高度最小为1吧


|