Algorithm: dynamic programming
1. Longest Increasing Subsequence (LIS) problem
unsorted array, calculate out the maximum length of subsequence with non-decreasing order.
lis[i] = lis[j] + 1 if arr[i] > arr[j]; lis[i] is the lis with arr[i] as the last element. so to get the maximum for the whole array, we should iterate the array and find out the max(lis[i])
complexity: O(n^2)
better algorithm: O(n logn): http://en.wikipedia.org/wiki/Longest_increasing_subsequence#Efficient_algorithms
2. Longest common subsequence
f[i][j] = f[i-1][j-1]+1 if s1[i-1] == s2[j-1]
max(f[i-1][j], f[i][j-1]) else
3. edit distance
f[i][j] = f[i-1][j-1] if f[i-1] == f[j-1];
min(f[i-1][j], min(f[i][j-1], f[i-1][j-1])) + 1;
4. coin change
N cents, infinitely supply S = {S1, S2, ... Sm}, how many way to change it?
f[i][j] = f[i-s[j]][j] + f[i][j-1], i: the cents, j: using 0 to j Sj to change it.
5. matrix chain multiplication
for (L = 2; L < n; L++) { // L is the chain length
for (int i = 1; i <= n-L+1; i++) {
j = i+L-1;
m[i][j] = INT_MAX;
for (int k = i; k <= j-1; k++) {
q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
m[i][j] = min(m[i][j], q);
}
}
}
return m[1][n-1];
Algorithm: dynamic programming的更多相关文章
- [Algorithm -- Dynamic Programming] Recursive Staircase Problem
For example there is a staricase N = 3 | ---| |---| | |---| | ---| ...
- [Algorithm -- Dynamic programming] How Many Ways to Decode This Message?
For example we have 'a' -> 1 'b' -> 2 .. 'z' -> 26 By given "12", we can decode t ...
- [Algorithm] Dynamic programming: Find Sets Of Numbers That Add Up To 16
For a given array, we try to find set of pair which sums up as the given target number. For example, ...
- 以计算斐波那契数列为例说说动态规划算法(Dynamic Programming Algorithm Overlapping subproblems Optimal substructure Memoization Tabulation)
动态规划(Dynamic Programming)是求解决策过程(decision process)最优化的数学方法.它的名字和动态没有关系,是Richard Bellman为了唬人而取的. 动态规划 ...
- Dynamic Programming
We began our study of algorithmic techniques with greedy algorithms, which in some sense form the mo ...
- Dynamic Programming: From novice to advanced
作者:Dumitru 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProg An impo ...
- [算法]动态规划(Dynamic programming)
转载请注明原创:http://www.cnblogs.com/StartoverX/p/4603173.html Dynamic Programming的Programming指的不是程序而是一种表格 ...
- hdu 4972 A simple dynamic programming problem(高效)
pid=4972" target="_blank" style="">题目链接:hdu 4972 A simple dynamic progra ...
- Julia is a high-level, high-performance dynamic programming language for technical computing, with syntax that is familiar to users of other technical
http://julialang.org/ julia | source | downloads | docs | blog | community | teaching | publications ...
随机推荐
- 课程设计之"网络考试系统"(php、Extjs)
1.TestSystem大概结构框图 2.数据库设计(11张表) 数据库名称:db_testsystem 数据库表: tb_admin 记录题库管理员帐户信息 代码 tb_allcontent 记录随 ...
- MFC中 SDI/MDI框架各部分指针获取方式
VC MFC SDI/MDI框架各部分指针获取方式 整理总结一下,希望能帮助到别人. 获得CWinApp 获得CMainFrame 获得CChildFrame 获得CDocument 获得CV ...
- EasyMvc入门教程-基本控件说明(5)小图标
我们网页很多时候需要小图标来进行美化,EasyMvc默认提供了100多种常用小图标,您可以根据实际情况选择使用,请看下面的例子: @Html.Q().Ico().Type(EasyMvcHelper. ...
- C# 的概念
1,C#-ASP.NET C# 的概念 2,Intro ASP.NET 一,基本概念: 1,C#--语言 microsoft 开发的纯面向对象的语言,是VS2005的主流开发语言. 语言的发展 C-- ...
- C#反射获取属性值和设置属性值
/// /// 获取类中的属性值 /// public string GetModelValue(string FieldName, object obj) { try { Type Ts = obj ...
- Node.js学习入门手册
Node.js 安装 1.下载http://nodejs.org/dist/v0.12.1/node-v0.12.1-x86.msi并完成安装 2.下载https://www.python.org/f ...
- AutoCAD如何将dwf转成dwg格式
dwf转成dwg怎么转, 悬赏分:30 - 解决时间:2009-11-22 10:19 重金:dwf转成dwg怎么转, 我是用在出图上的. 最佳答案 Design Web Format (DWF) 文 ...
- 【Excle数据透视表】如何隐藏数据透视表中行字段的”+/-”按钮
如下图:新建的数据透视表中有存在"+/-"符号,导致数据透视图不太美观,那么怎么处理呢? 解决方案 单击"显示"组中的"+/-"按钮显示或隐 ...
- Linux视频培训教程
很详尽的Linux培训教程,既包含日常工作常常要用到的实践及技巧,又包含Linux认证及系统管理及架构,讲的很不错.最关键的.这么具体,完整的教程还是免费的.花了点时间拿它整理了下. 第一部分: Li ...
- c#中使用ABCpdf处理PDF,so easy
QQ交流群:276874828 (ABCpdf ) 这几天项目中需要将页面导成PDF,刚开始使用iTextSharp,觉得在分页处理上比较复杂,后来无意中看到了ABCpdf,使用非常简单,并将一些常 ...