当前位置:网站首页>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 
边栏推荐
- Interview questions for software testing - a collection of interview questions for large factories in 2022
- Drools dynamically add, modify, and delete rules
- Go learning notes - go based interprocess communication
- Use sqoop to export ads layer data to MySQL
- 中国交通标志检测数据集
- About asp Net MVC project in local vs running response time is too long to access, the solution!
- C#修饰符
- JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
- China traffic sign detection data set
- 线性DP AcWing 896. 最长上升子序列 II
猜你喜欢
![[ybtoj advanced training guide] similar string [string] [simulation]](/img/eb/acfefc7f85018fe9365d13502e2b0a.jpg)
[ybtoj advanced training guide] similar string [string] [simulation]

The differences and relationships among port, targetport, nodeport and containerport in kubenetes

ArrayList与LinkedList效率的对比

应用LNK306GN-TL 转换器、非隔离电源
![JDBC prevent SQL injection problems and solutions [preparedstatement]](/img/32/f71f5a31cdf710704267ff100b85d7.png)
JDBC prevent SQL injection problems and solutions [preparedstatement]

Performance tuning project case

Redis sentinel mechanism and configuration

Hash table acwing 840 Simulated hash table

Embedded Software Engineer career planning

8 examples of using date commands
随机推荐
OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
JSON序列化 与 解析
1380. Lucky numbers in the matrix [two-dimensional array, matrix]
Visual studio efficient and practical extension tools and plug-ins
[ybtoj advanced training guidance] cross the river [BFS]
ASP. Net MVC default configuration, if any, jumps to the corresponding program in the specified area
Anti shake throttle
LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
BOM DOM
绕过ObRegisterCallbacks需要驱动签名方法
获取文件版权信息
中国交通标志检测数据集
std::vector批量导入快速去重方法
Shutter encapsulated button
Input box assembly of the shutter package
8 examples of using date commands
一些突然迸发出的程序思想(模块化处理)
[FFH] little bear driver calling process (take calling LED light driver as an example)
深拷贝 事件总线