解析
先按左端点排序得到一个右端点的新队列,然后就可以发现:
所有合法的方案都是新队列的一个单调递增队列
然后就转化成了最长上升序列的问题
代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+100;
int m,n;
struct node{
int a,b;
bool operator < (const node y)const{return a<y.a;}
}p[N];
int q[N],ed=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&p[i].a,&p[i].b);
}
sort(p+1,p+1+n);
for(int i=1;i<=n;i++){
int x=p[i].b;
if(q[ed]<x) q[++ed]=x;
else{
int pl=upper_bound(q+1,q+1+ed,x)-q;
q[pl]=x;
}
}
printf("%d",ed);
}
/*
7
2 6
4 2
9 8
10 3
15 12
17 17
22 4
*/