最长递增子序列
来源:互联网 发布:三维接线软件 编辑:程序博客网 时间:2024/06/06 18:10
#include<iostream>
#include<vector>#include<math.h>
using namespace std;
vector<int>get(vector<int>&abc){
int len=abc.size();
vector<int> dp(len);
vector<int> res(len);
dp[0]=abc[0];
res[0]=1;
int right=0;
int l=0;
int r=0;
for(int i =1;i<len;++i){
l=0;
r=right;
while(l<=r){
int mid=(l+r)/2;
if(abc[i]>dp[mid]) l=mid+1;
else r=mid-1;
}
right=max(right,l);
dp[l]=abc[i];
res[i]=l+1;
}
return res;
}
int main(){
vector<int> a={1,3,2,6,7,8,9,0};
vector<int>b(4);
b =get(a);
cout<<b[0]<<" "<<b[1]<<" "<<b[2]<<" "<<b[3]<<" "<<b[4]<<" "<<b[5]<<" "<<b[6]<<" "<<b[7];
return 0;
}
阅读全文
0 0
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 最长递增子序列
- 日历
- python中NumPy的常见用法
- 【Linux】Mysql初始化root密码和允许远程访问
- freemarker在servlet中的使用
- You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
- 最长递增子序列
- C++ 控制台打印无输出 无法查找或打开PDB文件
- Spring集成redis缓存
- 【1】coreML入门之结合ARKit场景展示
- Hdu-6183 Color it(cdq分治)
- 关于C#中readonly的变量赋值问题。
- Java
- laravel 添加触发事件
- php curl请求https接口返回curl: (60) SSL certificate problem: unable to get local issuer certificate 错误