90分 #1WA蒟蒻很茫然

P1434 [SHOI2002] 滑雪

jixiang @ 2021-05-26 15:54:48

#include<bits/stdc++.h>
using namespace std;
const int MAXN =100000;
int r,c;
int f[MAXN];
int num[MAXN];
int ans;
int dir[5];

struct node{
    int high,num;
    void input(int x)
    {
        scanf("%d",&high);
        num=x;
    }

}a[100009];

bool cmp(node x,node y)
{
    return x.high<y.high;
}

int main()
{
    cin>>r>>c;
    int x;

    dir[1]=1;dir[2]=-1;
    dir[3]=c;dir[4]=-c;

    for(int i=1;i<=r*c;i++)
    {
        a[i].input(i);
        num[i]=a[i].high;
        f[i]=1;
    }

    sort(a+1,a+1+r*c,cmp);

    for(int i=1;i<=r*c;i++)
    {
        x=a[i].num;

        for(int k=1;k<=4;k++)
        {
            if(x+dir[k]<=0||x+dir[k]>r*c)continue;
            if(x%c==0&&k==1)continue;
            if(x-1%c==0&&k==2)continue;

            if(num[x+dir[k]]<num[x])
            f[x]=max(f[x],f[x+dir[k]]+1);
        } 
    }

    for(int i=1;i<=r*c;++i)ans=max(ans,f[i]);
    cout<<ans;

    //for(int i=1;i<=r*c;i++)cout<<num[i]<<" "<<f[i]<<endl;

} 

by 阿丑 @ 2021-05-26 16:51:09

@jixiang if(x-1%c==0&&k==2)continue; 这么写的话会优先计算 1%c,再算 x-1%c,就是说最后的结果都是 x-1


by 阿丑 @ 2021-05-26 16:51:57

% 的优先级比 + 高。


by jixiang @ 2021-05-26 17:31:48

@阿丑 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 谢谢大佬!!!!!


by xingxuxin @ 2021-05-26 17:46:09

%%%orz

jx爆切dp


|