救民于水火
x-hechengye
2022-08-06 14:11:25
2022-08-06 14:53:57
15
返回题目
#include <bits/stdc++.h>
using namespace std;
int n, dp[5050][3];
struct cheng {
int a, b;
} c[5050];
bool cmp(cheng x, cheng y) { return x.a < y.a; }
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> c[i].a >> c[i].b;
}
dp[0][2] = -1;
sort(c + 1, c + n + 1, cmp);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
if (dp[j][2] < c[i].b) {
if (dp[j][1] + 1 > dp[i][1]) {
dp[i][1] = dp[j][1] + 1;
dp[i][2] = c[i].b;
}
}
}
}
int ans = -1;
for (int i = 1; i <= n; i++) {
ans = max(ans, dp[i][1]);
}
cout << ans;
return 0;
}
{{ vote && vote.total.up }}