LeetCode Longest Increasing Subsequence (LIS O(nlogn))
题意:
给一个数组,求严格递增的最长递增子序列的长度。
思路:
开销是一个额外的O(n)的数组。lower_bound(begin,end,val)的功能是:返回第一个大于等于val的地址。
class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
if(nums.empty()) return ;
int *p=new int[nums.size()];
p[]=nums[];
int len=;
for(int i=; i<nums.size(); i++)
{
if(nums[i]>p[len])
p[++len]=nums[i];
else
*lower_bound(p,p+len+,nums[i])=nums[i];
}
delete []p;
return ++len;
}
};
AC代码
LeetCode Longest Increasing Subsequence (LIS O(nlogn))的更多相关文章
- POJ 2533 Longest Ordered Subsequence(LIS模版题)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 47465 Acc ...
- LeetCode -- Longest Increasing Subsequence(LIS)
Question: Given an unsorted array of integers, find the length of longest increasing subsequence. Fo ...
- LeetCode OJ:Longest Increasing Subsequence(最长递增序列)
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- [LeetCode] Longest Increasing Subsequence 最长递增子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- [LeetCode] Longest Increasing Subsequence
Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest incre ...
- 65.Longest Increasing Subsequence(最长增长子序列)
Level: Medium 题目描述: Given an unsorted array of integers, find the length of longest increasing sub ...
- HPU第三次积分赛-D:Longest Increasing Subsequence(DP)
Longest Increasing Subsequence 描述 给出一组长度为n的序列,a1,a2,a3,a4...an, 求出这个序列长度为k的严格递增子序列的个数 输入 第一行输入T ...
- Poj 2533 Longest Ordered Subsequence(LIS)
一.Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- Longest Increasing Subsequence(DP)
public static int LIS(List<Integer> al) { int[] arr = new int[al.size()]; int lis = 0; arr[0] ...
随机推荐
- [转]Windows的窗口刷新机制
1.Windows的窗口刷新管理 窗口句柄(HWND)都是由操作系统内核管理的,系统内部有一个z-order序列,记录着当前窗口从屏幕底部(假象的从屏幕到眼睛的方向),到屏幕最高层的一个窗口句柄的排序 ...
- oracle Redhat64 安装错误3
问题描述 /usr/bin/ld: cannot find -lxxx 其中xxx即表示函式库文件名称,其命名规则是:lib+库名(即xxx)+.so. 可能原因: 1 安装了,但相对应的lib版本 ...
- POJ 1125 Stockbroker Grapevine 最短路 难度:0
http://poj.org/problem?id=1125 #include <iostream> #include <cstring> using namespace st ...
- LA 3516 - Exploring Pyramids
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- 学习KMP算法的一点小心得
KMP算法应用于 在一篇有n个字母的文档中 查找某个想要查找的长度为m的单词:暴力枚举:从文档的前m个字母和单词对比,然后是第2到m+1个,然后是第3到m+2个:这样算法复杂度最坏就达到了O(m*n) ...
- python下的复杂网络编程包networkx的安装及使用
由于py3.x与工具包的兼容问题,这里采用py2.7 1.python下的复杂网络编程包networkx的使用: http://blog.sina.com.cn/s/blog_720448d30101 ...
- 用K2 smartforms开发一个应用程序究竟比ASP.NET快多少?
这次试验的起因是一场内部辩论. “用K2 smartforms开发一个应用程序究竟比ASP.NET快多少?” 我们推测是快4倍. 但是经过测试发现,我们推测错了. 本文记录了试验的规划.过程以及令人惊 ...
- 关于BIOS的一点东西
关于BIOS的一点东西 编辑删除转载2016-05-20 00:36:36 去把BIOS的每个单词意思都有道一遍就都明白了,BOOT是更改 启动顺序的(台式机一直按del键就会进入BIOS界面,用上下 ...
- JAVA 打印九九乘法表
/** * * @author liangxiaoyu * @version 1.0 *2015-09-18 */public class JJ { public static void main( ...
- C# 3.0 扩展方法[转载]
实践 扩展方法是C# 3.0中新加入的特性.MSDN中对扩展方法的定义是:扩展方法使您能够向现有类型"添加"方法,而无需创建新的派生类型.重新编译或以其他方式修改原始类型. 以下以 ...