当前位置:网站首页>(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;
}
边栏推荐
- Cisco private dynamic routing protocol: EIGRP
- Single page pull-down refresh and double page pull-down refresh of MUI
- Altium designer工程下多个原理图和PCB图的一一对应
- sonarqube介绍和安装步骤
- sonarqube介紹和安裝步驟
- 2022年安全員-A證考題模擬考試平臺操作
- 【delphi】判断文件的编码方式(ANSI、Unicode、UTF8、UnicodeBIG)
- [Day8 literature extensive reading] space and time in the child's mind: evidence for a cross dimensional symmetry
- Wechat applet Bluetooth development
- 2022年高处安装、维护、拆除操作证考试题库模拟考试平台操作
猜你喜欢

2022年高处安装、维护、拆除操作证考试题库模拟考试平台操作

2022年安全员-A证考题模拟考试平台操作
![Delete the receiving address [project mall]](/img/3d/60819a1a8c36fd0c1014f91fe80470.png)
Delete the receiving address [project mall]

On the knowledge points of cookie attributes and the differences between webstorage and cookies?

Huawei cloud, OBS

Integrate工具之Jenkins

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

Live broadcast preview | featurestore meetup V3 is coming!

Wake up wrist - neural network and deep learning (tensorflow application) updating

Lake Shore - supertran VP continuous flow cryogenic thermostat system
随机推荐
Lake shore vnf series low temperature thermostat system - sample in flowing steam
How to make scripts executable anywhere
Queue (C language)
【delphi】判断文件的编码方式(ANSI、Unicode、UTF8、UnicodeBIG)
Lake Shore—SuperVariTemp 低温恒温器
Research Report on development trend and competitive strategy of global customized power supply industry
mysql5和mysql8同时安装
QR code
2022高压电工考试题模拟考试题库及在线模拟考试
Procédures d'introduction et d'installation de sonarqube
Top selling commodities 【 project mall 】
产品力进阶新作,全新第三代荣威RX5盲订开启
Unity3d C # development of wechat games audio / sound playback problem solving process sharing
postgresql10 进程
ETF operation record: March 1, 2022
2022年起重机司机(限桥式起重机)考试题模拟考试题库及模拟考试
Dblink operation in Oracle
El scrollbar display horizontal scroll bar
Jetpack架构组件学习(3)——Activity Results API使用
【Day9 文献泛读】On the (a)symmetry between the perception of time and space in large-scale environments