解题思路
代码
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
const int N = 5010;
PII a[N];
int f[N];
int n;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
sort(a, a + n);
int res = 0;
for (int i = 0; i < n; i++) {
f[i] = 1;
for (int j = 0; j < i; j++) {
if (a[j].second < a[i].second) f[i] = max(f[i], f[j] + 1);
}
res = max(res, f[i]);
}
cout << res << endl;
return 0;
}