今天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. noi 04:求整数的和与均值

    04:求整数的和与均值 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 读入n(1 <= n <= 10000)个整数,求它们的和与均值. 输入 ...

  2. Unity Mono IDE Setting

    Mac: 修改快捷键 删除一整行 Delete Entire Line    Command+D Format Document   Shift+Command+F 在文件中查找 Fin in Fil ...

  3. servlet获取参数时,request.getParameter("id")参数获取失败

    servlet获取参数时,request.getParameter("id")参数获取失败,这里的参数是“index”里面href中的参数 要注意,取不到值,是不是要取的参数有没有 ...

  4. poj 3190 Stall Reservations

    http://poj.org/problem?id=3190 Stall Reservations Time Limit: 1000MS   Memory Limit: 65536K Total Su ...

  5. Eclipse版本android 65535解决方案(原理等同android studio现在的分包方式)

    由于工作的需要看了下Eclipse下android65535的解决方案,查了好多文档,真心的发自内心的说一句请不要再拷贝别人的博客了,害人,真害人. 接下来我说下我的实现方式,首先说下65535的最可 ...

  6. SpringMVC 温故而知新

    http://www.cnblogs.com/bigdataZJ/p/5815467.html直接引用别人的吧,没时间呀

  7. 算法第四版 用eclipse实现书中UnionFind例子

    一 安装环境 直接下载algs4.exe 下载完成后C:\Users\zle 下面会有algs4 文件夹 原文: Our installer downloads, installs, and conf ...

  8. 关于在linux中使用图形界面的网络管理工具

    有好几种自动设置的工具可以选择(既然说是自动设置的工具,那就说明有手动设置的工具,例如 使用 ip, iw, iwconfig 这些命令设置网络),例如:Connman, netctl, Networ ...

  9. 安装fcitx [Crunch bang] [debian]

    第一步: sudo apt-get install fcitx fcitx-sunpinyin  fcitx-ui-classic fcitx-table fcitx-config-common fc ...

  10. PHP基础班初学心得:脑洞实验-JS变量存储函数与return的一些问题

    本人刚参加PHP基础班培训第一天,由于之前毫无基础,分享的心得可能不规范,方法也许也"旁门左道",不能保证质量,只作自己总结学习,也希望能帮助到同样是初学者的朋友们,共同进步. 在 ...