当前位置:网站首页>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 
边栏推荐
- AI mid stage technology research
- ASP. Net MVC default configuration, if any, jumps to the corresponding program in the specified area
- 线性DP AcWing 897. 最长公共子序列
- BOM DOM
- js 迭代器 生成器 异步代码处理 promise+生成器 -> await/async
- 上手报告|今天聊聊腾讯目前在用的微服务架构
- 防抖 节流
- Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime
- [FFH] little bear driver calling process (take calling LED light driver as an example)
- Redis bloom filter
猜你喜欢

Performance tuning project case

JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)

Redis bloom filter

染色法判定二分图 AcWing 860. 染色法判定二分图

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

Adding database driver to sqoop of cdh6

高性能纠删码编码

Hash table acwing 840 Simulated hash table
![2.6 using recursion and stack - [tower of Hanoi problem]](/img/fc/45038170dafd104691c93716b103cf.jpg)
2.6 using recursion and stack - [tower of Hanoi problem]

Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
随机推荐
About asp Net MVC project in local vs running response time is too long to access, the solution!
上手报告|今天聊聊腾讯目前在用的微服务架构
染色法判定二分图 AcWing 860. 染色法判定二分图
AI中台技术调研
Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)
Oracle从入门到精通(第4版)
Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand
Adding database driver to sqoop of cdh6
Floyd AcWing 854. Floyd求最短路
JDBC 预防sql注入问题与解决方法[PreparedStatement]
BOM DOM
About the loading of layer web spring layer components, the position of the layer is centered
Execute any method of any class through reflection
Day12 control flow if switch while do While guessing numbers game
Bom Dom
ArrayList与LinkedList效率的对比
Lekao: 22 year first-class fire engineer "technical practice" knowledge points
FBX import under ue4/ue5 runtime
3 A VTT端接 稳压器 NCP51200MNTXG资料
LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY