Dilworth定理
把一个数列划分成最少的最长不升子序列的数目就等于这个数列的最长上升子序列的长度
第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度,计算这套系统最多能拦截多少导弹,如果要拦截所有导弹最少要配备多少套这种导弹拦截系统。
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
vector<int> height;
int tem;
while (cin >> tem) height.push_back(tem);
int l[height.size()], len = 1, l1[height.size()], len1 = 1;
l[0] = height[0], l1[0] = height[0];
for (int i = 1; i < height.size(); ++i) {
if (height[i] <= l[len - 1])
l[len++] = height[i];
else {
int tem = upper_bound(l, l + len, height[i], greater<int>()) - l;
l[tem] = height[i];
}
if (height[i] > l1[len1 - 1])
l1[len1++] = height[i];
else {
int tem = lower_bound(l1, l1 + len1, height[i]) - l1;
l1[tem] = height[i];
}
}
cout << len << " " << len1;
return 0;
}