当前位置:网站首页>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 
边栏推荐
- IPhone 6 plus is listed in Apple's "retro products" list
- JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
- Drools terminates the execution of other rules after executing one rule
- Deep copy event bus
- Oracle从入门到精通(第4版)
- 百款拿来就能用的网页特效,不来看看吗?
- OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
- Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold
- 包管理工具
- Hash table acwing 840 Simulated hash table
猜你喜欢

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

spfa AcWing 852. spfa判断负环

Distributed machine learning framework and high-dimensional real-time recommendation system

Heap acwing 839 Simulated reactor

防抖 节流

js 迭代器 生成器 异步代码处理 promise+生成器 -> await/async
![[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)

Openssh remote enumeration username vulnerability (cve-2018-15473)

Simple understanding of ThreadLocal

Writing method of then part in drools
随机推荐
. Net, C # basic knowledge
MySQL and PostgreSQL methods to grab slow SQL
[ybtoj advanced training guidance] judgment overflow [error]
Programmers can't find jobs after the age of 35? After reading this article, you may be able to find the answer
Calculate the maximum path sum of binary tree
计数类DP AcWing 900. 整数划分
Floyd AcWing 854. Floyd求最短路
Do you know all the interface test interview questions?
线性DP AcWing 899. 编辑距离
Docker compose configuration mysql, redis, mongodb
Sweetheart leader: Wang Xinling
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
CV2 in OpenCV VideoWriter_ Fourcc() function and cv2 Combined use of videowriter() function
线性DP AcWing 895. 最长上升子序列
[FFH] little bear driver calling process (take calling LED light driver as an example)
Intel internal instructions - AVX and avx2 learning notes
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)