AtCoder Beginner Contest 134-E - Sequence Decomposing

(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;
}

 

posted @ 2019-07-21 10:54  晴天要下雨  阅读(345)  评论(0编辑  收藏  举报