提交时间:2022-07-19 12:47:12
运行 ID: 52542
#include <bits/stdc++.h> using namespace std; const int N=1e5+5; const int INF=1e9+10; int n; long long F[N]; struct Ban { long long l,r; } B[N]; bool cmp(const Ban x,const Ban y) { return x.l<y.l; } int main() { scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%lld%lld",&B[i].l,&B[i].r); sort(B+1,B+n+1,cmp); F[n]=1; long long ans=1; for(int i=n-1; i>=1; i--) { F[i]=-INF; for(int j=i+1; j<=n; j++) if(F[j]+1>F[i]&&B[j].r<=B[i].r) F[i]=F[j]+1; ans=max(ans,F[i]); } printf("%lld\n",ans); return 0; }