求助MLE!!20分

P1434 [SHOI2002] 滑雪

于正泽 @ 2018-10-17 23:09:25

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
using namespace std;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
int a[110][110],f[110][110];
int n,m;
int dfs(int x,int y)
{
    if(f[x][y]>0)return f[x][y];
    int i,ans=1,t;
    for(i=0;i<=3;i++)
    {
        int vx=dx[i]+x;
        int vy=dy[i]+y;
        if(vx<0||vx>n||vy<0||vy>m||a[vx][vy]<a[x][y])continue;
        t=dfs(vx,vy)+1;
        if(t>ans)ans=t;
    }
    f[x][y]=ans;
    return ans;
}
int main()
{
    int i,j;
    cin>>n>>m;
    memset(f,0,sizeof(f));
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)cin>>a[i][j];
    int maxn=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            f[i][j]=dfs(i,j);
            if(f[i][j]>maxn)maxn=f[i][j];
        }
    }
    //put
    cout<<maxn<<endl;
    return 0;
}

MLE 我很迷茫,求大佬指教


by 于正泽 @ 2018-10-17 23:13:53

等会儿


by 于正泽 @ 2018-10-17 23:15:06

我好像过了

if(vx<0||vx>n||vy<0||vy>m||a[vx][vy]<a[x][y])continue;

这一句改成

if(vx>0&&vx<=n&&vy>0&&vy<=m&&a[vx][vy]<a[x][y])
        {t=dfs(vx,vy)+1;
        if(t>ans)ans=t;}
就过了!!

by Sai0511 @ 2018-10-17 23:16:44

@于正泽
您试试改成

 if(vx<1||vx>n||vy<1||vy>m||a[vx][vy]<a[x][y])continue;

by 于正泽 @ 2018-10-20 07:22:15

貌似还是20分


by 于正泽 @ 2018-10-20 07:22:23

555~~~


by 于正泽 @ 2018-10-20 07:28:37

貌似还不对


by LevenKoko @ 2018-10-28 09:17:54

同求

if(......) continue就MLE

然而改成

if(......) dfs(fx,fy)就AC了


by LevenKoko @ 2018-10-28 09:18:05

@ZJQ90202


by LevenKoko @ 2018-10-28 09:18:16

@ZJQ90202


by LevenKoko @ 2018-10-28 09:18:40

@Judge_Cheung


|