Description
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
Input
Output
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
水题。。。求有几条LIS,直接开个数组,数组的每个元素用来存每条LIS的最小的元素,可以边读入边更新,更新的时候,从第一条LIS开始扫,看看能不能放入某一条LIS里面,如果所有的LIS都不能放入的话,就再开一条LIS。。。
代码:
# include <iostream>
# include <algorithm>
# include <cstdio>
# include <cstring>
using namespace std;
const int maxn = 1e5 + 5;
int d[maxn];
int n;
int main(void)
{
while (~scanf("%d", &n)) {
int x, p = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &x);
int t = 0;
while (t < p && d[t] < x) ++t;
if (t == p) d[p++] = x;
else d[t] = x;
}
printf("%d\n", p);
}
return 0;
}
146



被折叠的 条评论
为什么被折叠?



