题意:

  给一个数组,求严格递增的最长递增子序列的长度。

思路:

  开销是一个额外的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))的更多相关文章

  1. POJ 2533 Longest Ordered Subsequence(LIS模版题)

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 47465   Acc ...

  2. LeetCode -- Longest Increasing Subsequence(LIS)

    Question: Given an unsorted array of integers, find the length of longest increasing subsequence. Fo ...

  3. LeetCode OJ:Longest Increasing Subsequence(最长递增序列)

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  4. [LeetCode] Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  5. [LeetCode] Longest Increasing Subsequence

    Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest incre ...

  6. 65.Longest Increasing Subsequence(最长增长子序列)

    Level:   Medium 题目描述: Given an unsorted array of integers, find the length of longest increasing sub ...

  7. HPU第三次积分赛-D:Longest Increasing Subsequence(DP)

    Longest Increasing Subsequence 描述 给出一组长度为n的序列,a1​,a2​,a3​,a4​...an​, 求出这个序列长度为k的严格递增子序列的个数 输入 第一行输入T ...

  8. Poj 2533 Longest Ordered Subsequence(LIS)

    一.Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...

  9. Longest Increasing Subsequence(DP)

    public static int LIS(List<Integer> al) { int[] arr = new int[al.size()]; int lis = 0; arr[0] ...

随机推荐

  1. 【转】理解cookie和session机制

    cookie和session机制之间的区别与联系 具体来说cookie机制采用的是在客户端保持状态的方案.它是在用户端的会话状态的存贮机制,他需要用户打开客户端的cookie支持.cookie的作用就 ...

  2. 自定义Encoder/Decoder进行对象传递

    转载:http://blog.csdn.net/top_code/article/details/50901623 在上一篇文章中,我们使用Netty4本身自带的ObjectDecoder,Objec ...

  3. Spark(3) - External Data Source

    Introduction Spark provides a unified runtime for big data. HDFS, which is Hadoop's filesystem, is t ...

  4. 重点关注之OData with List

    OData是什么 官方解释:The Open Data Protocol (OData) is a data access protocol for the web. OData provides a ...

  5. GUID vs INT Debate【转】

    http://blogs.msdn.com/b/sqlserverfaq/archive/2010/05/27/guid-vs-int-debate.aspx I recently read a bl ...

  6. 在 Ubuntu 上配置高性能的 HHVM 环境

    HHVM全称为 HipHop Virtual Machine,它是一个开源虚拟机,用来运行由 Hack(一种编程语言)和 PHP 开发应用.HHVM 在保证了 PHP 程序员最关注的高灵活性的要求下, ...

  7. lazyload 分页加载

    http://www.neoease.com/lazy-load-jquery-plugin-delay-load-image/ echo $d['pic']; ?>" src=&qu ...

  8. 免费提供一些公开的SOCK4/5/HTTP/HTTPS代理服务器(经测试可以用)

    Last update IP address Port Country Type Anonymity 54 secs 116.228.55.217 8000 flag China HTTP High ...

  9. POJ 1050 To the Max 暴力,基础知识 难度:0

    http://poj.org/problem?id=1050 设sum[i][j]为从(1,1)到(i,j)的矩形中所有数字之和 首先处理出sum[i][j],此时左上角为(x1,y1),右下角为(x ...

  10. java获取页面编码

    文章出自:http://babyjoycry.javaeye.com/blog/587527 在此感谢原作者...\(^o^)/~   最近研究抓取网页内容,发现要获取页面的编码格式,Java没有现成 ...