样例是错的,大佬求助!!!

P1434 [SHOI2002] 滑雪

jennycai13 @ 2023-06-05 13:03:07

#include<bits/stdc++.h>
using namespace std;
const int N=105;
int tt,r,c,f[N][N],a[N][N];
int dx[]={0,1,-1,0},dy[]={1,0,0,-1};
struct T{
    int x,y,w;
}t[N];
bool cmp(T c,T d)
{
    return c.w<d.w;
}
int main()
{
    cin>>r>>c;
    for(int i=1;i<=r;i++)
    {
        for(int j=1;j<=c;j++)
        {
            cin>>a[i][j];
            ++tt;
            t[tt].x=i;
            t[tt].y=j;
            t[tt].w=a[i][j];
        }
    }
    sort(t+1,t+tt+1,cmp);
    f[t[1].x][t[1].y]=1;
    int ans=1;
    for(int i=2;i<=tt;i++)
    {
        int x=t[i].x,y=t[i].y;
        f[x][y]=1;
        for(int j=0;j<4;j++)
        {
            int xx=x+dx[j],yy=y+dy[j];
            if(xx>=1 and xx<=r and yy>=1 and yy<=c and a[xx][yy]>t[i].w)
            {
                f[xx][yy]=max(f[xx][yy],f[x][y]+1);
                ans=max(ans,f[xx][yy]);
            }
        }
    }
    cout<<ans;
}

by ForgotDream_CHN @ 2023-06-05 14:02:12

这题要记搜


by jennycai13 @ 2023-06-07 13:17:21

@ForgotDream_CHN AC了


|