Longest increasing substring (LIS)--DP
来源:互联网 发布:外汇交易软件下载 编辑:程序博客网 时间:2024/06/07 10:39
问题描述:
譬如 对于一个序列{1 2 3 3 5 4 6 2}
{1 2 3} {1 5 6} {1 2 2} {1 2 3 3 5 6}
都是它的不下降子序列 其中最后一个是最长的不下降子序列
动态规划:
用opt[i]来记录以a[i]为结尾的LIS的长度
以a[i]为结尾的LIS,可以表示为以a[j]为结尾的LIS+1(opt[j]+1)
其中a[j]为满足以下条件:
1.位置在a[i]前面
2.比a[i]小
3.opt[j]尽量最大
因此opt[i]可以用opt[j]来表示:
max(opt[j]) : j<i && a[j]<=a[i]
注意:并不是所有n的问题一定要转化为确定n-1的子问题,只要它的子问题在它之前被解决即可。
for i:=2to ndo
begin
for j:=1to i-1do
if (a[i]>=a[j])and(opt[j]>opt[i])
then opt[i]:=opt[j];
inc(opt[i]);
if opt[i]>ans
then ans:=opt[i];
end;
end;
阅读全文
0 0
- Longest increasing substring (LIS)--DP
- DP-LIS( Longest Increasing Subsequenc)
- DP中的LIS:longest increasing subsequence
- Longest Increasing Subsequence(LIS)
- Longest Increasing Subsequence(LIS)
- 最长上升子序列 LIS(Longest Increasing Subsequence)---DP
- Find longest increasing sequence (LIS)
- Longest Increasing Subsequence,LIS初步
- 【DP】 Longest Increasing Subsequence
- [DP]Longest Increasing Subsequence
- Longest increasing substring2 --DP
- [LIS]Longest Increasing Sequence:nlogn算法和两种普通DP的实现
- Longest Increasing Subsequence (LIS) 的java实现
- 最长非降子序列LIS(longest increasing subsequence)
- LeetCode Longest Increasing Subsequence DP
- 300. Longest Increasing Subsequence/DP
- Longest Palindromic Substring (DP)
- poj 1239 Increasing Sequences dp lis
- 不会玩Linux系统怎么找女朋友?
- Email_demo
- 位运算符和位运算(与,或,异或等)
- 空指针异常
- 机器学习实战:模型评估和优化
- Longest increasing substring (LIS)--DP
- 【书中示例】-《C程序设计语言》第三章:控制流
- lucene,搜索检索引擎
- Struts标签
- cartographer--ros配置
- leetcode---sqrtx---分治
- WEB网站常见的攻击方式总结与原理分析
- PHP逐行读取txt文件
- Longest increasing substring2 --DP