优化的最长上升子序列LIS算法 O(nlogn)
2013-11-04 20:13
225 查看
g[ x ] 记录的是 : g[ x ] = min { a[ i ] | 以a[ i ] 结尾的最长上升子序列长度是 x }, 若不存在这样的a[ i ] , g[ x ] = INF
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=1010,INF=(int)1e9; int a[maxn] , d[maxn] ,g[maxn]; int main() { int n; while(~scanf("%d",&n)){ for(int i=1;i<=n;i++) g[i] = INF; int M=1; for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n;i++) { int k= lower_bound(g+1,g+1+n,a[i]) - g; d[i] = k; g[k] = a[i]; M = max ( M , d[i]); } printf("%d\n",M); } return 0; }
相关文章推荐
- 最长不上升子序列的优化(nlogn)
- 最长上升子序列问题 nlogn 实现算法的简述
- 最长上升子序列 POJ 2533(n*n与 nlogn)
- HDU - 1025 Constructing Roads In JGShining's Kingdom (nlogn 最长上升子序列)
- 2016年团体程序设计天梯赛-决赛 L2-014. 列车调度 【导弹拦截系统-最长上升子序列nlogn求法】
- 【HDU 1950】Bridging signals(LIS算法求最长上升子序列)
- 【最长上升子序列LIS】O(n^2)和O(nlogn)算法简记
- C语言:最长上升子序列LIS算法实现
- 最长上升子序列O(nlogn)算法
- code vs 2188 最长上升子序列(线段树优化DP)
- NOJ1858 对于最长上升子序列O(nlogn)算法的深入理解
- 最长上升子序列O(nlogn)算法模板
- 【训练题】航线设计 | 使用最长上升子序列(LIS)长度的O(nlogn)算法优化
- 最长上升子序列LIS算法实现
- 蓝桥杯算法训练拦截导弹【最长上升子序列 & 最长非下降子序列nlogn 和 n^2】
- 最长上升子序列LIS算法实现
- HDU 1025 最长上升子序列(nlogn)
- 最长上升子序列O(NlogN)算法
- 最长上升子序列LIS算法粗略讲解
- hdu 5748 && poj 2533 最长上升子序列(o(nlogn)做法)