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] ...
随机推荐
- juery 选择器 选择多个元素
使用,号: $("#goodSource,#mailState") 选择了id为goodSource或者mailState的元素,当两者之间有任何一个有改变时,将会触发该操作. / ...
- C#常用的加密算法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 方法一: //须添加对System.Web的引用 ...
- 使用tomcat配置文件下载服务器,自定义下载列表
先上图,利用tomcat,这个下载界面没有代码,点击文件名即可下载 详细参考:http://tomcat.apache.org/tomcat-7.0-doc/default-servlet.html
- getParamValues()
http://blog.csdn.net/msg_java2011/article/details/6529226
- [Js]面向对象基础
一.什么是对象 对象是一个整体,对对外提供一些操作 二.什么是面向对象 使用对象时,只关注对象提供的功能,不关注其内部细节,比如Jquery 三.Js中面向对象的特点 1.抽象:抓住核心问题 2.封装 ...
- HDU 1698 Just a Hook
题意:初始1-n 值为1,有Q操作,每次可以把一段[l,r] 整段每个值变成 x,问最后的[1,n]总和. 线段树成段更新(基础题) #include<cstdio> #include&l ...
- [开发笔记]-WindowsService服务程序开发
Windows服务:Microsoft Windows 服务(即,以前的 NT服务)使您能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序.这些服务可以在计算机启动时自动启动,可 ...
- Program C--二分
My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...
- Android ContentProvider的实现
当Android中的应用需要访问其他应用的数据时,用ContentProvider可以很好的解决这个问题.今天介绍一下ContentProvider的用法. 首先开发ContentProvider有两 ...
- MATLAB axes
本帖由MATLAB技术论坛(http://www.matlabsky.com)原创,更多精彩内容参见http://www.matlabsky.com axes ★★★★★ 功能 创建坐标系图形对象 语 ...