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 ...
随机推荐
- nginx 配置静态目录 访问bootstrap
location /static/ { alias /Users/wangziqiang/djangoprojects/bpmTest/static/; } 注意 /static/ 中 /的完整 ...
- selenium firefox46.0.1设置禁用图片
firefox_profile = webdriver.FirefoxProfile()firefox_profile.set_preference('permissions.default.ima ...
- maven module和project的区别
Maven Project可以理解为父工程.Maven Module可以理解为子工程.创建Maven Module工程必须有存在的父工程,maven就是通过父子工程进行工程管理的.
- Ubuntu 14.04 使用VirtualBox 4.3.10 虚拟 Windows 7
Ubuntu 14.04 尽管不错,可是有些事仅仅能在Windows下才干完毕,所以在 Ubuntu 下利用虚拟机软件Oracle VirtualBox,虚拟安装个Windows系统是个不错的选择. ...
- JAVA Eclipse的Android文件结构是怎么样的
默认res目录下面存放了界面需要的布局和图片文件,之所以图片分为hdpi,ldpi,mdpi这些,是为了不同的设备准备的(高/中/低分辨率的图片) Bin目录类似于VS的debug或者releas ...
- AutoCAD如何移动零件和缩放零件图
如下图所示,我想要把这个零件放大并移动到图纸的中央,先全部选中这个零件,方法是在左上角点一下,然后拖出一个矩形包围整个零件 然后点击右侧的缩放命令,底部的命令栏变成指定基点的时候,在这个图纸的右上 ...
- React15.6.0实现Modal弹层组件
代码地址如下:http://www.demodashi.com/demo/12315.html 注:本文Demo环境使用的是我平时开发用的配置:这里是地址. 本文适合对象 了解React. 使用过we ...
- MVC初了解
MVC:Model-View-Controller,将数据和显示形式分离. Model:能够看做是三层中的D层+B层,实现业务逻辑和与数据库的交互. View:看做是U层,用来显示数据. Contro ...
- Java的Executor框架和线程池实现原理
Java的Executor框架 1,Executor接口 public interface Executor { void execute(Runnable command); } Executor接 ...
- Spark源码分析之一:Job提交运行总流程概述
Spark是一个基于内存的分布式计算框架,运行在其上的应用程序,按照Action被划分为一个个Job,而Job提交运行的总流程,大致分为两个阶段: 1.Stage划分与提交 (1)Job按照RDD之间 ...