AtCoder Beginner Contest 134-E - Sequence Decomposing

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

AtCoder Beginner Contest 134-E - Sequence Decomposing

AtCoder Beginner Contest 134-E - Sequence Decomposing

 

 题意:找出最小个数的最长上升子序列

思路:找出最长上升子序列的最小个数,只需要找出每个最小上升子序列的最后一个元素,然后元素个数之和就是最长上升子序列的最小个数

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

 

上一篇:java – 使用JNLP部署Applet


下一篇:WPF Beginner - Drag&Drop Item in listview