当前位置:网站首页>(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;
}
边栏推荐
- 2022年低压电工上岗证题目及在线模拟考试
- ETF operation record: March 1, 2022
- HMS core shows the latest open capabilities in mwc2022, helping developers build high-quality applications
- El scrollbar display horizontal scroll bar
- 【Day6-7 文献精读】A unifying Bayesian framework accounting for spatiotemporal interferences with a ...
- sonarqube介绍和安装步骤
- [day3 literature intensive reading] Oriental time and space interaction in tau and kappa effects
- 免费分享1个新媒体运营必备的宝藏网站
- swiper
- 2022 safety officer-a certificate test question simulation test platform operation
猜你喜欢

Wireless communication comparison of si4463, si4438 and Si4432 schemes of wireless data transmission module

05 classification learning notes lihongyi's in-depth study 2021

Jetpack architecture component learning (3) -- activity results API usage
![Vs code writing assembly code [microcomputer principle]](/img/fc/e32262fcd80841ba7b82882a89ad0b.png)
Vs code writing assembly code [microcomputer principle]

移印工艺流程及应用注意事项

2022年安全员-A证考题模拟考试平台操作

【Day9 文献泛读】On the (a)symmetry between the perception of time and space in large-scale environments

2022 safety officer-b certificate theoretical question bank and simulation test

CVPR 2022 | meta learning performance in image regression task

Application of Lora wireless communication module Lora technology in smart home light control
随机推荐
Stack (C language)
Implementation scheme of iteration and combination pattern for general tree structure
swiper
Jetpack架构组件学习(3)——Activity Results API使用
[day4 literature intensive reading] space – time interdependence: evidence against Asymmetric mapping between time and space
Here we go! Dragon lizard community enters PKU classroom
Read the logstash principle
[day1/5 literature intensive reading] speed constancy or only slowness: what drives the kappa effect
El scrollbar display horizontal scroll bar
Postgresql10 process
loading
Node version control tool NVM
Wechat applet Bluetooth development
Custom font settings
Handwritten simple promise
2022年R1快开门式压力容器操作考题及在线模拟考试
Jetpack architecture component learning (3) -- activity results API usage
Jetpack architecture component learning (3) -- activity results API usage
How to make scripts executable anywhere
2022年高处安装、维护、拆除操作证考试题库模拟考试平台操作