Luo Gu P1020 missile interceptors solution to a problem LIS expand title Dilworth Theorem

Topic links: https://www.luogu.com.cn/problem/P1020

Topic effect:
to give you a bunch of number, ask:

  1. This does not increase the number of sub-string length of the longest sequence;
  2. Minimum sub-sequence is divided into a number of these sequences are not rising sequence.

The first problem is relatively simple, method is to use binary O (log n) can solve this problem.

The second problem, you can use Dilworth theorem:

The minimum number of division in a sequence, does not increase the longest sequence which is equal to the length of the longest sequence rising

Reference from Dilworth Theorem: https://www.cnblogs.com/ZDHYXZ/p/6871802.html

Codes are as follows:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, cnt, a[maxn], h[maxn], ans;
int main() {
    while (~scanf("%d", &a[n])) n ++;
    for (int i = 0; i < n; i ++) {
        int id = upper_bound(h, h+cnt, a[i], greater<int>()) - h;
        if (id == cnt) h[cnt++] = a[i];
        else h[id] = a[i];
    }
    ans = cnt;
    cnt = 0;
    for (int i = 0; i < n; i ++) {
        int id = lower_bound(h, h+cnt, a[i]) - h;
        if (id == cnt) h[cnt++] = a[i];
        else h[id] = a[i];
    }
    printf("%d\n%d\n", ans, cnt);
    return 0;
}

Guess you like

Origin www.cnblogs.com/quanjun/p/12071921.html