练习题1:最长上升子序列 - 题目 - Online Judge (haizeix.com)
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<int> ans;
int bs(int target) {
int head = 0, tail = ans.size() - 1, mid = 0;
while (head < tail) {
mid = (head + tail) / 2;
if (ans[mid] < target) head = mid + 1;
else tail = mid;
}
return head;
}
int main() {
int n;
cin >> n;
for (int i = 1, a; i <= n; i++) {
cin >> a;
if (ans.empty()) ans.push_back(a);
else if (a > ans[ans.size() - 1]) ans.push_back(a);
else ans[bs(a)] = a;
}
cout << ans.size();
return 0;
}