AtCoder初心者コンテスト134-E - シーケンス分解

https://atcoder.jp/contests/abc134/tasks/abc134_e

 

 質問の意味:数の最も長いシーケンス最小の増加を見つけます

アイデア:最長シーケンスの数の最小の増加を見つけることは、だけにして各シーケンス、要素数の最後の要素の中で最小の増加を見つける必要があるとの数の最小の上昇の最も長いシーケンスであります

#include <iostream>
#include<set>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn =1e5+10;
int a[maxn];
multiset<int> q;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    for(int i=1;i<=n;i++)
    {
        multiset<int>:: iterator it =q.lower_bound(a[i]);
        if(it==q.begin())
            q.insert(a[i]);
        else
        {
            it--;
            q.erase(it);
            q.insert(a[i]);
        }
    }
    cout << q.size();
    return 0;
}

 

おすすめ

転載: www.cnblogs.com/wjc2021/p/11220483.html