最长不下降子序列【模板】
#include<bits/stdc++.h>
#define int long long
using namespace std;
int len,n,a[100009],g[100009];
signed main(){
scanf("%ld",&n);
for(int i=1;i<=n;i++) cin>>a[i];
len=1;
for(int i=2;i<=n;++i){
if(g[len]<=a[i]){
g[++len]=a[i];
}else{
for(int j=1;j<=len;j++){
if(g[j]>a[i]){
g[j]=a[i];
break;
}
}
}
}
cout<<len-1;
return 0;
}
本文来自博客园,作者:Arthur_Douglas,转载请注明原文链接:https://www.cnblogs.com/wenzhihao2023/p/17991534