80求调

P1434 [SHOI2002] 滑雪

DKsniper @ 2024-01-24 12:04:27

#include<cstdio>
#include<cstring>
using namespace std;
int c,r,a[105][105],zc[105][105],fx[8][2]={{0,1},{0,-1},{-1,-1},{-1,0},{-1,1},{1,-1},{1,0},{1,1}},wz[10010][2],h,t,t1,ans=-1;
void dfs(int x,int y)
{
    for(int j=0;j<8;j++)
    {
        int xx=x+fx[j][0],yy=y+fx[j][1];
        if(xx>0 && xx<=r && yy>0 && yy<=c)
        {
            if(a[xx][yy]<a[x][y] && zc[xx][yy]<zc[x][y]+1)
            {
                zc[xx][yy]=zc[x][y]+1;
                dfs(xx,yy);
            }
        }
    }
}
int main()
{
    scanf("%d%d",&r,&c);
    for(int i=1;i<=r;i++)
    {
        for(int j=1;j<=c;j++)
        {
            zc[i][j]=1;
            scanf("%d",&a[i][j]);
        }
    }
    for(int i=1;i<=r;i++)
    {
        for(int j=1;j<=c;j++)
        {
            dfs(i,j);
        }
    }
    for(int i=1;i<=r;i++)
    {
        for(int j=1;j<=c;j++)
        {
            if(zc[i][j]>ans)
            {

                ans=zc[i][j];
            }
        }

    }
    printf("%d",ans);
}

by KEZEQIAN @ 2024-01-26 21:59:12

xx>0 && xx<=r && yy>0 && yy<=c 这里改成 xx>=0 && xx<=r && yy>=0 && yy<=c


by DKsniper @ 2024-02-01 20:17:44

@KEZEQIAN

还是80


by KEZEQIAN @ 2024-02-02 00:16:24

@DKsniper public static void dfs(int x,int y) { for(int i=0;i<4;i++) { int dx=a[i]+x; int dy=b[i]+y; if((dx>=0 && dx<=n && dy>=0 && dy<=m ) && map[dx][dy]<map[x][y] && s[dx][dy]<s[x][y]+1) { s[dx][dy]=s[x][y]+1; dfs(dx, dy); } }


by KEZEQIAN @ 2024-02-02 00:18:14

@DKsniper 超时还是wa


by DKsniper @ 2024-02-02 21:19:49

@KEZEQIAN

WA


by KEZEQIAN @ 2024-02-02 21:59:25

@DKsniper 偏移数组换成两个一维


|