Luogu P1020 missile interception

There is no topic here, the main writing method

Topic link: https://www.luogu.org/problem/show?pid=1020

 

Dilwroth's theorem.

Application: Find the minimum number of subsequences that cover the entire sequence without descending

Standard LIS, use upper_bound(), the initial value is assigned the maximum

 1 int lis(){
 2     maxloc=0;
 3     memset(seqend,0x3,sizeof(seqend));
 4     loop(i,cnt){
 5         int* loc=upper_bound(seqend+1,seqend+n+1,num[i]);
 6         *loc=num[i];
 7         maxloc=max(maxloc,int(loc-endp));
 8     }
 9     return maxloc;
10 }

 

Dilworth, use lower_bound(), the initial value is assigned the smallest

int dilworth(){
    maxloc=0;
    memset(seqend,-1,sizeof(seqend));
    loop(i,cnt){
        int* loc=lower_bound(seqend+1,seqend+n+1,num[i],greater<int>());
        *loc=num[i];
        maxloc=max(maxloc,int(loc-endp));
    }
    return maxloc;
}

 

max(int, long) will not match, so a cast is required. (long is the default pointer subtraction value)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325296712&siteId=291194637