当前位置:网站首页>(linear DP | monotone queue) acwing 895 Longest ascending subsequence
(linear DP | monotone queue) acwing 895 Longest ascending subsequence
2022-06-11 23:34:00 【Age worry】
895. Longest ascending subsequence
Topic link https://www.acwing.com/problem/content/897/
subject :
Method 1 :dp
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a[1010],c[1010];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int res=0;
for(int i=1;i<=n;i++){
for(int j=1;j<i;j++){
if(a[j]<a[i])
c[i]=max(c[i],c[j]);
}
c[i]+=1;
res=max(res,c[i]);
}
cout<<res;
return 0;
}
Method 2 : A monotonous queue
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a[1010],k;
int erfen(int u){
int l=0,r=k;
while(l<r){
int mid=l+r+1>>1;
if(a[mid]<u) l=mid;
else r=mid-1;
}
return l;
}
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
int t;
scanf("%d",&t);
int index=erfen(t);
a[++index]=t;
k=max(k,index);
}
cout<<k;
return 0;
}
边栏推荐
- Teacher lihongyi, NTU -- tips for DNN regulation
- JS common method collection
- 抗原產品進入家庭,中國醫療器械企業迎來新藍海
- Discrete mathematics attention points, priority problems
- New Year Countdown JS case
- Vs code writing assembly code [microcomputer principle]
- Top selling commodities 【 project mall 】
- [day6-7 intensive literature reading] a unifying Bayesian framework accounting for spatiotemporal interactions with a
- 2022高压电工考试题模拟考试题库及在线模拟考试
- A method of relay for ultra long distance wireless transmission of low power wireless module
猜你喜欢

sonarqube介紹和安裝步驟

Software installation and use, etc

Introduction to Solr Basics

HMS core shows the latest open capabilities in mwc2022, helping developers build high-quality applications

HMS core shows the latest open capabilities in mwc2022, helping developers build high-quality applications

Implementation scheme of iteration and combination pattern for general tree structure

2022年安全员-B证理论题库及模拟考试

2022年低压电工上岗证题目及在线模拟考试
![[day3 literature intensive reading] Oriental time and space interaction in tau and kappa effects](/img/90/4470dca9b19dbcd0f99655f7d9d23e.png)
[day3 literature intensive reading] Oriental time and space interaction in tau and kappa effects

思科私有动态路由协议:EIGRP
随机推荐
Wake up wrist - neural network and deep learning (tensorflow application) updating
Common problems of Converged Communication published in February | Yunxin small class
Unity3d C#开发微信小游戏音频/音效播放问题解决过程分享
Lake Shore—SuperVariTemp 低温恒温器
Research Report on development trend and competitive strategy of global customized power supply industry
El select drop-down box style combined with El table (pseudo) combined with drop-down selection
Application of Lora technology in long distance wireless transmission of water meter reading
Delete the receiving address [project mall]
Single page pull-down refresh and double page pull-down refresh of MUI
[Day2 intensive literature reading] time in the mind: using space to think about time
Simulated examination question bank and simulated examination of 2022 crane driver (limited to bridge crane)
2022年安全员-B证理论题库及模拟考试
What are the pitfalls of redis's current network: using a cache and paying for disk failures?
Here we go! Dragon lizard community enters PKU classroom
loading
New Year Countdown JS case
Wireless communication comparison of si4463, si4438 and Si4432 schemes of wireless data transmission module
Les produits antigéniques entrent dans la famille et les entreprises chinoises de dispositifs médicaux accueillent un nouvel océan bleu
El scrollbar display horizontal scroll bar
Lake Shore VNF 系列低温恒温器系统——流动蒸汽中的样品