提交时间:2022-07-19 12:01:25
运行 ID: 52366
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn=1e5+10; const int INF=1e9; struct Node{ int left; int right; }wood[maxn]; int ans; int n; void dfs(int left,int right,int ptr,int num){ if(ptr==n){ ans=max(ans,num); return ; } if(left<=wood[ptr].left and wood[ptr].right<=right){ dfs(wood[ptr].left,wood[ptr].right,ptr+1,num+1); dfs(left,right,ptr+1,num); } else{ dfs(left,right,ptr+1,num); } } main(){ cin>>n; for(int i=0;i<n;i++){ cin>>wood[i].left>>wood[i].right; } dfs(0,INF,0,0); cout<<ans; } /* 2 4 3 8 2 3 7 7 3 8 4 4 */