最长上升子序列
来源:互联网 发布:veleq电气仿真软件 编辑:程序博客网 时间:2024/05/16 01:28
最长上升子序列(LCS) 模板
复杂度 o(nlog(n))
#include <iostream>#include <vector>#include <map>#include <algorithm>using namespace std;void Binary_Insert(int ar[],int &len,int x){ if(x > ar[len-1]) { ar[len] = x; len++; return ; } int l = 0,r = len-1; int mid; while(r >= l) { mid = l + ((r-l)>>1); if(ar[mid] > x) r = mid-1; else l = mid+1; } ar[l] = x;}template <class It>int n_lisLength(It begin,It end){ typedef typename iterator_traits<It>::value_type T; T inf = 1<<30; vector<T> best(end-begin,inf); for(It i = begin; i != end; ++i) *lower_bound(best.begin(),best.end(),*i) = *i; return lower_bound(best.begin(),best.end(),inf) - best.begin();}int main () { cout<<(!!0)<<endl; int br[10] = {0,2,3,1,7,8,9,6,5,4}; cout<<n_lisLength(br,br+10)<<endl; int ar[1000]; int len = 1; for(int i = 0;i <= 10; ++i) ar[i] = 1000; ar[0] = br[0]; for(int i = 1;i < 10; ++i) Binary_Insert(ar,len,br[i]); for(int i = 0;i < len; ++i) cout<<ar[i]<<" "; return 0;}
阅读全文
0 0
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 乐趣:p++和**k
- Qt如何弹出子窗口以及注意事项(某位大神的讲解)
- 内核态和用户态
- K:找寻数组中第n大的数组元素的值的三个算法
- 开发了一个小工具
- 最长上升子序列
- 设置MongoDB成Windows服务
- Java基础:编码格式
- K:找寻最长子序列的四个算法
- PL/SQL之一 基础语法
- Leetcode-606. Construct String from Binary Tree
- IO-读写文件
- HTML 显示网页图片 若无法显示图片则显示文字
- 在Myeclipse或者eclipse下创建tld文件步骤详解: