longest incresing sequence
动态规划基本题目,longest incresing sequence,找出序列中的最长递增子序列;
例如给出序列{8,3,5,2,4,9,7,11},
其中最长递增子序列为{3,5,9,11}或{3,5,7,11}或{3,4,9,11}或{3,4,7,11},子序列按元素递增,序列长度都为4;
子问题:第i处的最长子序列问题
定义问题:
阶段:后序,到第i项为阶段i;
状态:到i处的最长子序列为dp[i];
决策:dp[i]=max{dp[j]}+1,i<j<=n,a[i]<a[j]
有了上述公式既可以建立动态表dp;
Array | 8 | 3 | 5 | 2 | 4 | 9 | 7 | 11 |
dp | 3 | 4 | 3 | 4 | 3 | 2 | 2 | 1 |
代码之后给出
longest incresing sequence的更多相关文章
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- Binary Tree Longest Consecutive Sequence
Given a binary tree, find the length of the longest consecutive sequence path (连续的路径,不是从小到大). The pa ...
- 128. Longest Consecutive Sequence(leetcode)
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- ACM Longest Repeated Sequence
Description You are given a sequence of integers, A = a1, a2, ... an. A consecutive subsequence of A ...
- [LintCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. H ...
- LeetCode Binary Tree Longest Consecutive Sequence
原题链接在这里:https://leetcode.com/problems/binary-tree-longest-consecutive-sequence/ 题目: Given a binary t ...
- 24. Longest Consecutive Sequence
Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest con ...
- 【leetcode】Longest Consecutive Sequence
Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest con ...
随机推荐
- Oracle语句优化规则(二)
21. 用EXISTS替换DISTINCT 当提交一个包含一对多表信息(比如部门表和雇员表)的查询时,避免在SELECT子句中使用DISTINCT. 一般可以考虑用EXIST替换 例如: ...
- ThinkPHP第十二天(Import导入第三方类库方法,独立分组文件夹结构)
1.Import(路径+类名,基础路径): 平时导入类时有三种基础路径:Think:import('Think.core.Action');Think表示ThinkPHP/Lib基础路径,完整路径为T ...
- werkzeug中reloader的实现
在用flask开发时,如果把use_reloader设为True(debug设为True也能实现),那当你修改了app代码或调用环境发生改变时,服务器会自动重启,如下 * Detected chang ...
- Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer'
@Configuration public class HttpSessionConfig { @Bean public static ConfigureRedisAction configureRe ...
- Android Dalvik 虚拟机
简介 Android 平台虽然是使用java语言来开发应用程序,但Android程序却不是运行在标准java虚拟机上的.谷歌专门为Android平台设计了一套虚拟机来运行Android程序.它就是Da ...
- Putty远程登录VMware虚拟机Linux(Ubuntu12.04)
为了不至于来回在Win7和Ubuntu12.04之间来回切换,在Win7下使用VMware9.0安装了Ubuntu12.04. 首先下载Vmware9.0虚拟机软件,下载地址为:VMware-work ...
- POJ 1741 Tree【Tree,点分治】
树上的算法真的很有意思……哈哈. 给一棵边带权树,问两点之间的距离小于等于K的点对有多少个. 将无根树转化成有根树进行观察.满足条件的点对有两种情况:两个点的路径横跨树根,两个点位于同一颗子树中. 如 ...
- Spring基于 Annotation 的简单介绍
tyle="margin:20px 0px 0px; font-size:14px; line-height:26px; font-family:Arial"> 1.使用 @ ...
- CentOS下mysql最大连接数设置 1040 too many connection
当最大连接数比較小时,可能会出现"1040 too many connection"错误. 能够通过改动配置文件来改动最大连接数,但我连配置文件在哪都不知道,应该怎么办呢? 首先须 ...
- __get __set 实例
<?php class Person { //下面是人的成员属性,都是封装的私有成员 private $name; //人的名子 private $sex; //人的性别 private $ag ...