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 ...
随机推荐
- Python学习之day4
参考文献:http://www.cnblogs.com/alex3714/articles/5143440.html 迭代器: 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直 ...
- html(第一天,div+css)
一.CSS布局属性 Width:设置对象的宽度(width:45px). Height:设置对象的高度(Height:45px;). Background:设置对象的背景颜色.背景图像. 1.背景颜色 ...
- shell学习之变量、判断、重复动作
1.1 环境以及变量的定义.赋值.展开.删除 export:将一个变量导入到环境中:export PATH=$PATH:/home. readonly 讲一个变量设置为只读模式,在shell脚本中定义 ...
- USB接口定义
一般的排列方式是:红白绿黑从左到右 定义: 红色-USB电源 标有-VCC.Power.5V.5VSB字样 绿色-USB数据线(正)-DATA+.USBD+.PD+.USBDT+ 白色-USB数据线( ...
- Shell中的正则表达式及字符串处理
shell里一个正则表达式就是由普通字符(例如字符 a 到 z)以及特殊字符(称为元字符)组成的文字模式.该模式描述在查找文字主体时待匹配的一个或多个字符串.正则表达式作为一个模板,将某个字符模式与所 ...
- isdigit()判断是不是数字
string 里面的函数isdigit(),可以判断是不是数字. 或者,采用type(1)==int.
- 配置greenplum参数
在进行一个greenplum安装之前需要进行配置一下相关的系统参数,否则很容易出现意想不到的错误. 1.修改系统参数 编辑 /etc/sysctl.conf ,以下是最小配置 kernel.shmma ...
- 同步fifo的verilogHDL设计实例
原创 设计一个fifo,输入16bit,输出16bit的data,寻址宽度5bit,有空满标志. top 层如下所示: /* date : 2014/10/14 version : modelsim ...
- tomcat配置管理用户名密码
tomcat6默认是将用户是注释的 配置文件在根目录下/conf/tomcat-users.xml文件中 配置默认如下: <!-- <role rolename="tomcat ...
- Python函数式编程:内置函数map()使用说明
一.概述 map操作是函数式编程中的重要技术之一,其作用就是对一个集合中的每个元素做处理,生成一个新的元素,由这些新的元素组成一个新的集合的返回. 所以map操作后,产生的新集合的元素个数和原集合的元 ...