当前位置:网站首页>Linear DP acwing 896 Longest ascending subsequence II
Linear DP acwing 896 Longest ascending subsequence II
2022-07-02 12:43:00 【T_ Y_ F666】
linear DP AcWing 896. Longest ascending subsequence II
Original link
AcWing 896. Longest ascending subsequence II
Algorithm tags
greedy
Ideas

For length is 1 Suborder of , Can be stored a[1], It can also be stored a[2], however a[2] Is better than a[1], Because if the subsequent numbers can be compared with a[1] Constitute ascending subsequence , Then it must be possible to a[2] Constitute ascending subsequence , Therefore, the storage length is i The minimum value at the end of the ascending sequence , Using the method of counter evidence, we can get that the ending value rises with the length of the longest rising sequence .
simulation

Time complexity
For ordered arrays , Find the maximum value less than a certain number , You can use dichotomy , Search efficiency log(n), n Queries , The time complexity is n ∗ l o g ( n ) n*log(n) n∗log(n)
Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 100005, INF = 0x3f3f3f3f;
int a[N], q[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read();
rep(i, 0, n){
a[i]=read();
}
int len=0;
rep(i, 0, n){
int l=0, r=len;
while(l<r){
int mid=l+r+1>>1;
if(q[mid]<a[i]){
l=mid;
}else{
r=mid-1;
}
}
len=max(len, r+1);
q[r+1]=a[i];
}
printf("%lld", len);
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- JDBC prevent SQL injection problems and solutions [preparedstatement]
- 上手报告|今天聊聊腾讯目前在用的微服务架构
- H5 to app
- spfa AcWing 851. SPFA finding the shortest path
- Window10 upgrade encountered a big hole error code: 0xc000000e perfect solution
- Is the neural network (pinn) with embedded physical knowledge a pit?
- Go learning notes - go based interprocess communication
- Leetcode - Sword finger offer 59 - I, 59 - II
- 通过反射执行任意类的任意方法
- 百款拿来就能用的网页特效,不来看看吗?
猜你喜欢
![2.6 using recursion and stack - [tower of Hanoi problem]](/img/fc/45038170dafd104691c93716b103cf.jpg)
2.6 using recursion and stack - [tower of Hanoi problem]

Hash table acwing 840 Simulated hash table

Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime

Redis sentinel mechanism and configuration

What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT

哈希表 AcWing 841. 字符串哈希

Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand

AI mid stage technology research

上手报告|今天聊聊腾讯目前在用的微服务架构

Distributed machine learning framework and high-dimensional real-time recommendation system
随机推荐
Leetcode - Sword finger offer 37, 38
arcgis js 4. Add pictures to x map
JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
Window10 upgrade encountered a big hole error code: 0xc000000e perfect solution
Simple understanding of ThreadLocal
Rust search server, rust quick service finding tutorial
Shuttle encapsulated AppBar
js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
About the loading of layer web spring layer components, the position of the layer is centered
区间DP AcWing 282. 石子合并
Intel 内部指令 --- AVX和AVX2学习笔记
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
Deep copy event bus
CPU指令集介绍
Distributed machine learning framework and high-dimensional real-time recommendation system
8A 同步降压稳压器 TPS568230RJER_规格信息
spfa AcWing 851. SPFA finding the shortest path
软件测试面试题-2022年大厂面试题合集
Interview questions for software testing - a collection of interview questions for large factories in 2022
Is the neural network (pinn) with embedded physical knowledge a pit?