【題解】CSES 1145 Increasing Subsequence

【題目敘述】https://cses.fi/problemset/task/1145/
【解題想法】DP

#include <iostream>
#include <vector>
using namespace std;
 
int n, x;
vector <int> v;
 
int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> x;
        if (v.empty() || x > v.back()) v.push_back(x);
        else *lower_bound(v.begin(), v.end(), x) = x;
    }
    cout << v.size();
}
分享本文 Share with friends