题意
给出NNN个东西,每个东西有值A,BA,BA,B,求出最大子集使Ai≥Aj,Bi≤BjA_i\geq A_j,B_i\leq B_jAi≥Aj,Bi≤Bj这个条件不满足。
思路
既然是使不满足这个条件,就以AAA为第一关键字从小到大排,BBB从大到小排。
然后求BBB的LISLISLIS。
代码
#include<cstdio>
#include<algorithm>
struct node {
int a, b;
}c[100001];
int n, ans;
int f[100001];
bool operator <(const node &a, const node &b) {
return a.a < b.a || a.a == b.a && a.b > b.b;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d %d", &c[i].a, &c[i].b);
std::sort(c + 1, c + n + 1);
int len = 1;
f[1] = c[1].b;
for (int i = 2; i <= n; i++) {
if (c[i].b > f[len]) f[++len] = c[i].b;
else f[std::lower_bound(f + 1, f + len + 1, c[i].b) - f] = c[i].b;
}
printf("%d", len);
}