提交时间:2022-07-19 12:25:15
运行 ID: 52510
#include <iostream> #include <algorithm> using namespace std; int n; struct muban{ int l,r; }a[405]; bool cmp(muban x,muban y){ return x.l<y.l; } int ans=0; bool u[405]; void dfs(int d,int p,int ll,int rr){ if(d>n){ ans=max(ans,p); // cout<<d<<" "<<p<<" "<<ll<<" "<<rr<<endl; return ; } for(int i=d;i<=n;i++){ if(n-i+1+p<=ans){ // cout<<d<<" "<<p<<" "<<ll<<" "<<rr<<endl; ans=max(ans,p); return ; } if(a[i].l>=ll && a[i].r<=rr && !u[i]){ // cout<<ll<<" "<<rr<<" "<<a[i].l<<" "<<a[i].r<<" "<<p<<endl; ans=max(ans,p); u[i]=1; dfs(d+1,p+1,a[i].l,a[i].r); } u[i]=0; dfs(d+1,p,ll,rr); } } int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i].l>>a[i].r; } sort(a+1,a+n+1,cmp); int xx=1e9; dfs(1,0,0,xx); cout<<ans<<endl; return 0; }