当前位置:网站首页>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 
边栏推荐
- Win10 system OmniPeek wireless packet capturing network card driver failed to install due to digital signature problem solution
- Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
- Mongodb redis differences
- LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
- Leetcode - Sword finger offer 59 - I, 59 - II
- About asp Net MVC project in local vs running response time is too long to access, the solution!
- ASP. Net MVC default configuration, if any, jumps to the corresponding program in the specified area
- 防抖 节流
- Heap acwing 839 Simulated reactor
- 线性DP AcWing 897. 最长公共子序列
猜你喜欢
![2.7 binary tree, post order traversal - [FBI tree]](/img/6b/1ded3632cc69329d7b2762ce47fdbc.jpg)
2.7 binary tree, post order traversal - [FBI tree]

线性DP AcWing 895. 最长上升子序列

PR 2021 quick start tutorial, learn about the and functions of the timeline panel

JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))

LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY

Rust search server, rust quick service finding tutorial

JSON序列化 与 解析

Programmers can't find jobs after the age of 35? After reading this article, you may be able to find the answer
![2.6 using recursion and stack - [tower of Hanoi problem]](/img/fc/45038170dafd104691c93716b103cf.jpg)
2.6 using recursion and stack - [tower of Hanoi problem]
![[FFH] little bear driver calling process (take calling LED light driver as an example)](/img/e7/153ae9f1befc12825d277620049f9d.jpg)
[FFH] little bear driver calling process (take calling LED light driver as an example)
随机推荐
浏览器存储方案
Input box assembly of the shutter package
VLAN experiment
The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night
Heap acwing 838 Heap sort
spfa AcWing 852. spfa判断负环
线性DP AcWing 902. 最短编辑距离
高性能纠删码编码
H5 to app
应用LNK306GN-TL 转换器、非隔离电源
Visual studio efficient and practical extension tools and plug-ins
分布式机器学习框架与高维实时推荐系统
LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
Js10day (API phased completion, regular expression introduction, custom attributes, filtering sensitive word cases, registration module verification cases)
Win10 system OmniPeek wireless packet capturing network card driver failed to install due to digital signature problem solution
Oracle从入门到精通(第4版)
Adding database driver to sqoop of cdh6
一些突然迸发出的程序思想(模块化处理)
浏览器node事件循环
"As a junior college student, I found out how difficult it is to counter attack after graduation."