1. 程式人生 > >最長上升子序列和不下降子序列

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

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