#include <bits/stdc++.h>

using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0);

int n;

int LIS(vector<int> &a)
{
    vector<int> b;
    for(auto x: a)
    {
        auto it=lower_bound(b.begin(), b.end(), x);
        if(it==b.end()) b.push_back(x);
        else *it=x;
    }
    return b.size();
}

int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    cout<<LIS(a)<<"\n";
    return 0;
}

最长上升子序列问题,数组b中存最优的末尾值,我们贪心地去找第一个大于等于它的值,找到就替换

#牛客春招刷题训练营#