最长上升子序列和不下降子序列

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013200703/article/details/85374252
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <fstream>
#include <stdlib.h>
#include <time.h>
#include <sstream>
using namespace std;


int a[110];
// 1 3 4
int main1() {
    int n;
    while (cin >> n) {
        set<int> s;
        for (int i = 0;i < n;i ++) {
            cin >> a[i];
        }
        for (int i = 0;i < n;i ++) {
            auto p = s.lower_bound(a[i]);
            if (p != s.end()) {
                s.erase(p);
            }
            s.insert(a[i]);
        }
        cout << s.size() << endl;
    }
}

// 1 1 3 4
int main() {
    int n;
    while (cin >> n) {
        multiset<int> s;
        for (int i = 0;i < n;i ++) {
            cin >> a[i];
        }
        for (int i = 0;i < n;i ++) {
            auto p = s.upper_bound(a[i]);
            if (p != s.end()) {
                s.erase(p);
            }
            s.insert(a[i]);
        }
        cout << s.size() << endl;
    }
}

猜你喜欢

转载自blog.csdn.net/u013200703/article/details/85374252