宜昌营销型网站/app拉新平台有哪些
1134 最长递增子序列
给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的)
例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。
Input
第1行:1个数N,N为序列的长度(2 <= N <= 50000) 第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= S[i] <= 10^9)
Output
输出最长递增子序列的长度。
Input示例
8 5 1 6 8 2 4 5 10
Output示例
5
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main() {int n = 0, buf = 0, max = 0;scanf("%d", &n);vector<int>a;vector<int>::iterator it;while(n--) {scanf("%d", &buf);if((it = upper_bound(a.begin(), a.end(), buf)) == a.end()) {a.push_back(buf);max++;} else {*it = buf;}}printf("%d\n", max);return 0;
}