题目连接:https://www.luogu.com.cn/problem/P1020html
题目大意:
给你一串数,求:c++
第一个问题比较简单,就是用二分的方法 O(log n) 能够解决这个问题。spa
第二个问题,能够用 Dilworth定理 证实:code
在一个序列中,最长不上升子序列的最少划分数就等于其最长上升子序列的长度htm
Dilworth定理参考自:http://www.javashuo.com/article/p-zsdtwnnm-hc.htmlblog
实现代码以下:get
#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; }