最开始求 a 数组的时候,太搞人心态了
细想,细想
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 5e3 + 100;
int a[N],c[N],f[N];
struct Node{
int x, y;
bool operator < (const Node &A) const
{
return x < A.x;
}
}b[N];
int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> b[i].x >> b[i].y;
c[i] = b[i].y;
}
sort(b, b+n);
sort(c, c+n);
for(int i = 0; i < n; i++)
a[i] = lower_bound(c,c+n,b[i].y)-c;
int ans = 1;
for(int i = 0; i < n; i++)
{
f[i] = 1;
for(int j = i; j >= 0; j--)
{
if(a[i] > a[j]) f[i] = max(f[i], f[j]+1);
}
}
for(int i = 0; i < n; i++) ans = max(ans, f[i]);
cout << ans;
}