友好城市(最长上升子序列)

#include <iostream>
#include <algorithm>

using namespace std;

typedef pair<int, int> PII;

const int N = 5010;

int n;
PII city[N];
int f[N];

int main()
{
    
    
    scanf("%d", &n);
    for (int i = 0; i < n; i ++ ) scanf("%d%d", &city[i].first, &city[i].second);
    sort(city, city + n);

    int res = 0;
    for (int i = 0; i < n; i ++ )
    {
    
    
        f[i] = 1;
        for (int j = 0; j < i; j ++ )
            if(city[j].second<city[i].second)
              f[i]=max(f[i],f[j]+1);
        res = max(res, f[i]);
    }

    printf("%d\n", res);

    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43738331/article/details/112854316