直接上代码:
#include <bits/stdc++.h>
using namespace std;
struct c{int a, b, l;} d[5005];
bool cmp(c num1, c num2) {return num1.a < num2.a;}
int n, ans = 0;
void dp(int x) {
if(!x) return;
d[x].l = 1;
for(int i = x + 1; i <= n; ++i)
if(d[x].b <= d[i].b && d[x].l <= d[i].l)
d[x].l = d[i].l + 1;
ans = max(ans, d[x].l);
dp(x - 1);
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) scanf("%d%d", &d[i].a, &d[i].b);
sort(d + 1, d + 1 + n, cmp);
dp(n);
printf("%d", ans);
return 0;
}