提交时间:2022-07-19 11:51:25
运行 ID: 52265
#include <bits/stdc++.h> using namespace std; struct Wood { int l,r; } wood[500001]; int Cmp(Wood a,Wood b) { return a.l == b.l ? a.r < b.r : a.l < b.l; } int Max,i,j,longest = 1; int dp[500001]; int a[500001]; int main() { int n; scanf("%d",&n); for(i = 1;i <= n;i++) scanf("%d%d",&wood[i].l,&wood[i].r); sort(wood + 1,wood + 1 + n,Cmp); for(int i = 1;i <= n;i++) a[i] = wood[i].r,dp[i] = 1; // for(int i = 1;i <= n;i++) printf("%d\n",a[i]); for(int i = 2;i <= n;i++) { bool flag = false; for(int j = 1;j < i;j++) if(a[i] <= a[j]) dp[i] = max(dp[i],dp[j]),flag = true; if(flag) dp[i]++; } // for(int i = 1;i <= n;i++) printf("%d\n",dp[i]); printf("%d\n",dp[n]); return 0; }