今天528给讲了基础的DP,其中第一道例题就是最长不下降子序列——LIS。

题目简述:给出N个数,求最长不下降子序列的长度。

数据范围:30% N<=1000 ; 100% N<=100000.

首先30%的数据很容易,可以想到一个N2的算法:

用f[i]表示以i结尾的最长不下降子序列的长度最长为多少,推出动态转移方程:f[i]=max(f[j])+1(a[i]>=a[j]&&j<i)

BUT!看看数据就知道,只能拿30分,这个O(n2)的效率显然只能拿部分分。怎么办呢,祭出O(n log n)算法!铛铛!

用f[n]表示最长不下降子序列长度为n的序列末尾最小值为多少,然后我们转移的时候就可以二分,二分最长不下降子序列的长度,然后与f[mid]比较,得出答案。用答案更新f数组。

可以做做 http://www.rqnoj.cn/problem/167 这题,是个纯裸的LIS。

About LIS(Longest Increasing Subsequence)的更多相关文章

  1. 最长上升子序列 LIS(Longest Increasing Subsequence)

    引出: 问题描述:给出一个序列a1,a2,a3,a4,a5,a6,a7….an,求它的一个子序列(设为s1,s2,…sn),使得这个子序列满足这样的性质,s1<s2<s3<…< ...

  2. 最长递增子序列 (LIS) Longest Increasing Subsequence

    问题描述: 有一个长为n的数列a0, a1,..., an-1.请求出这个序列中最长的上升子序列.请求出这个序列中最长的上升子序列. 上升子序列:对于任意i<j都满足ai<aj的子序列. ...

  3. 最长上升子序列(LIS: Longest Increasing Subsequence)

    示例: 输入: [10,9,2,5,3,7,101,18] 输出: 4 解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4. 从网上找的一段代码(我由java改为了C++版本),原作者 ...

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

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

  5. 300最长上升子序列 · Longest Increasing Subsequence

    [抄题]: 往上走台阶 最长上升子序列问题是在一个无序的给定序列中找到一个尽可能长的由低到高排列的子序列,这种子序列不一定是连续的或者唯一的. 样例 给出 [5,4,1,2,3],LIS 是 [1,2 ...

  6. 【Lintcode】076.Longest Increasing Subsequence

    题目: Given a sequence of integers, find the longest increasing subsequence (LIS). You code should ret ...

  7. [tem]Longest Increasing Subsequence(LIS)

    Longest Increasing Subsequence(LIS) 一个美丽的名字 非常经典的线性结构dp [朴素]:O(n^2) d(i)=max{0,d(j) :j<i&& ...

  8. The Longest Increasing Subsequence (LIS)

    传送门 The task is to find the length of the longest subsequence in a given array of integers such that ...

  9. 300. Longest Increasing Subsequence(LIS最长递增子序列 动态规划)

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

随机推荐

  1. 区间K 大数查询

      算法训练 区间k大数查询   时间限制:1.0s   内存限制:256.0MB 问题描述 给定一个序列,每次询问序列中第l个数到第r个数中第K大的数是哪个. 输入格式 第一行包含一个数n,表示序列 ...

  2. laravel5.3----------调度任务以及Artisan

    1.在使用的过程中会遇到有些函数不能用需要在php配置文件里面打开: disable_functions = exec,passthru,popen,proc_open,shell_exec,syst ...

  3. 使用JFinal的第一个项目出现的问题(The return type is incompatible with JspSourceDependent.getDependants())

    四月 08, 2016 4:35:34 下午 org.apache.catalina.core.ApplicationDispatcher invoke严重: Servlet.service() fo ...

  4. Oracle EBS APIs

    参考链接: http://blog.csdn.net/pan_tian/article/details/7754598 http://blog.itpub.net/26687597/viewspace ...

  5. mono支持gb2312

    需要安装mono-locale-extras 输入命令 yum install -y mono-locale-extras 安装即可

  6. 移动设备如何打开RMS加密的文档

    关键字:RMS. AZure RMS.IPhone.Android.Office365.Sharepoint.Exchange 最近总是碰到要求用苹果手机及安卓手机阅读RMS加密文档的需求,经过查找相 ...

  7. UVa 11235 RMQ

    首先讲一下RMQ算法的意思. RMQ(Range Minimum Query,RMQ)范围最小值,给出一个n个元素的数组,计算min(A[L],A[L+1],...,A[R-1],A[R]): 这里运 ...

  8. MVC配置ckeditor+ckfinder

    ckeditor当前使用版本:4.5.8 ckfinder当前使用版本:2.6.0 1.Ckeditor配置简单,直接使用Nuget下载就可 2.下载ckfinder https://cksource ...

  9. Redmine开发帮助

    这里先零星记录二次开发用得上的知识点: 1.windows下开发环境,参考此文.最好使用rubyinstaller安装,注意选择版本.或者直接安装railsinstaller. 2.获取自定义内容,参 ...

  10. 用 正则表达式 限定XML simpleType 定义

    <xsd:simpleType name="ResTrictions"> <xsd:restriction base="xsd:string" ...