#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<int>arr(n);
for (int i = ; i < n; ++i)
cin >> arr[i];
vector<int>stk;//模拟堆栈
stk.push_back(arr[]);
for (int i = ; i < n; ++i) {
if (arr[i] > stk.back())//如果该元素大于栈顶元素,将该元素入栈
stk.push_back(arr[i]);
else//替换掉第一个大于或者等于这个数字的那个数
*lower_bound(stk.begin(), stk.end(), arr[i]) = arr[i];
}
cout << stk.size() << endl;
return ;
}
#include <iostream>
#include <algorithm>
using namespace std;
const int N = ;
int n;
int a[N];
int q[N];//所有不同长度下上升序列的结尾的最小值(也就是,第一个数的最小)
int main() {
scanf("%d", &n);
for (int i = ; i < n; i ++ ) scanf("%d", &a[i]);
int len = ;//q里面的元素个数 ,最开始为0,一个都没有
q[] = -2e9;
for (int i = ; i < n; i ++ ) {//枚举每个数字
int l = , r = len;
while (l < r) { //二分出来小于a[i] 之前的 数字中最大的数字
int mid = l + r + >> ;
if (q[mid] < a[i]) l = mid;
else r = mid - ;
}
len = max(len, r + );//r找的是可以接在哪个长度的后面
q[r + ] = a[i];
}
printf("%d\n", len);
return ;
}

AcWing 896. 最长上升子序列 II的更多相关文章

  1. AcWing 895. 最长上升子序列

    //设上升序列的最后一个数字为第i个,那么就以第i-1个位分类标准, //i-1可以没有,也可以是在数组中下标为1,下标为2 //一直到下标为i-1的数字 #include <iostream& ...

  2. AcWing 897. 最长公共子序列

    #include <iostream> #include <algorithm> using namespace std; ; int n, m; char a[N], b[N ...

  3. lintcode 最长上升连续子序列 II(二维最长上升连续序列)

    题目链接:http://www.lintcode.com/zh-cn/problem/longest-increasing-continuous-subsequence-ii/ 最长上升连续子序列 I ...

  4. Java实现 LeetCode 522 最长特殊序列 II(查找最长的非子序列的长度)

    522. 最长特殊序列 II 给定字符串列表,你需要从它们中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些 ...

  5. UVA10599:Robots(II)(最长上升子序列)

    Your company provides robots that can be used to pick up litter from fields after sporting events an ...

  6. [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  7. P1439 【模板】最长公共子序列

    题目描述 给出1-n的两个排列P1和P2,求它们的最长公共子序列. 输入输出格式 输入格式: 第一行是一个数n, 接下来两行,每行为n个数,为自然数1-n的一个排列. 输出格式: 一个数,即最长公共子 ...

  8. [HAOI2007]上升序列(最长上升子序列)

    题目描述 对于一个给定的 S=\{a_1,a_2,a_3,…,a_n\}S={a1​,a2​,a3​,…,an​} ,若有 P=\{a_{x_1},a_{x_2},a_{x_3},…,a_{x_m}\ ...

  9. HDOJ1025(最长上升子序列)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

随机推荐

  1. Python 用户输入&while循环 初学者笔记

    input() 获取用户输入(获取的都是字符串哦) //函数input()让程序停止运行,等待用户输入一些文本. //不同于C的是可在input中添加用户提示,而scanf不具备这一特性. //提示超 ...

  2. docker镜像下载出现:received unexpected HTTP status: 500 Internal Server Error

    1.镜像下载总是出现报错:received unexpected HTTP status: 500 Internal Server Error 2.尝试多种方法: ①阿里云docke加速器:注册之后, ...

  3. 中软国际首届嘉年华晚会 创新网络年会PK“春晚”

    随着新年脚步的来临,各大公司的年会陆续出炉,但是中软国际的首届嘉年华晚会,以创新网络年会和全国八地同步进行的模式,演绎不一样的互联网年会,简直可以PK“春晚”.IT届中最漂亮的美女热舞,程序员中最会唱 ...

  4. TCP常用拆包处理

    1.演示环境为windows 10 1903 2.演示代码 #include "pch.h" #include <iostream> #include <WinS ...

  5. 粒子群算法优化BP生物能神经网络

    定义: 粒子群中每个粒子的位置表示BP神经网络当前迭代中权值的集合,每个粒子的维数由网络中起连接作用的权值的数量和阈值个数决定,以给定训练样本集的神经网络输出误差作为神经网络训练问题的适应度函数,适应 ...

  6. C++-蓝桥杯-矩阵乘法[快速幂]

    忘了改矩阵的大小居然还有33分,我醉了 #include <cstdio> ; struct Matrix{int a[N][N];}; int n,m; Matrix A,O,I; Ma ...

  7. C++-POJ3233-Matrix Power Series[矩阵乘法][快速幂]

    构造矩阵 #include <cstdio> ; struct Matrix{int a[MAXN][MAXN];}O,I;int N; ;i<MAXN;i++);j<MAXN ...

  8. MySQL的聚合函数

    MySQL的聚合函数 网站:https://www.runoob.com/mysql/mysql-functions.html 函数名 功能描述 count() 计数 sum() 求和 avg() 平 ...

  9. vue 多组件路由处理方法

    实现页面: 实现效果: 实现代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

  10. vue制作滚动条幅-跑马灯效果实例代码

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...