Dynamic Programming
We began our study of algorithmic techniques with greedy algorithms, which in some sense form the most natural approach to algorithm design. Faced with a new computational problem, we've seen that it's not hard to propose multiple possible greedy algorithms; the challenge is then to determine whether any of these algorithms provides a correct solution to the problem in all cases.
6.1 Weighted Interval Scheduling: A Recursive Procedure
We have seen that a particular greedy algorithm produces an optimal solution to the Interval Scheduling Problem, where the goal is to accept as large a set of nonoverlapping intervals as possible. The weighted Interval Scheduling Problem is a strictly more general version, in which each interval has a certain value (or weight), and we want to accept a set of maximum value.
Designing a Recursive Algorithm
Since the original Interval Scheduling Problem is simply the special case in which all values are equal to 1, we know already that most greedy algorithms will not solve this problem optimally. But even the algorithm that worked before (repeatedly choosing the interval that ends earliest) is no longer optimal in this more general setting.
Indeed, no natural greedy algorithm is known for this problem, which is what motivates our switch to dynamic programming. As discussed above, we will begin our introduction to dynamic programming with a recursive type of algorithm for this problem, and then in the next section we'll move to a more iterative method that is closer to the style we use in the rest of this chapter.
We use the notation from our discussion of Interval Scheduling. We have
Let's suppose that the requests are sorted in order of nondecreasing finish time:
Now, given an instance of the Weighted Interval Scheduling Problem, let's consider an optimal solution
On the other hand, if
All this suggests that finding the optimal solution on intervals
And how do we decide whether
Request
These facts form the first crucial component on which a dynamic programming solution is based: a recurrence equation that expresses the optimal solution (or its value) in terms of the optimal solutions to smaller subproblems.
Despite the simple reasoning that led to this point, (1) is already a significant development. It directly gives us a recursive algorithm to compute
|
If Return Else Return Endif |
The correctness of the algorithm follows directly by induction on
Proof. By definition
Unfortunately, if we really implemented the algorithm
Memoizing the Recursion
In fact, though, we're not so far from having a polynomial-time algorithm. A fundamental observation, which forms the second crucial component of a dynamic programming solution, is that our recursive algorithm
How could we eliminate all this redundancy? We could store the value of memoization.
We implement the above strategy in the more “intelligent” procedure
|
If Return Else if Return Else Define Return Endif |
Analyzing the Memoized Version
Clearly, this looks very similar to our previous implementation of the algorithm; however, memoization has brought the running time way down.
The running time of
Dynamic Programming的更多相关文章
- 动态规划 Dynamic Programming
March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...
- HDU 4223 Dynamic Programming?(最小连续子序列和的绝对值O(NlogN))
传送门 Description Dynamic Programming, short for DP, is the favorite of iSea. It is a method for solvi ...
- hdu 4223 Dynamic Programming?
Dynamic Programming? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- 算法导论学习-Dynamic Programming
转载自:http://blog.csdn.net/speedme/article/details/24231197 1. 什么是动态规划 ------------------------------- ...
- Dynamic Programming: From novice to advanced
作者:Dumitru 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProg An impo ...
- HDU-4972 A simple dynamic programming problem
http://acm.hdu.edu.cn/showproblem.php?pid=4972 ++和+1还是有区别的,不可大意. A simple dynamic programming proble ...
- [算法]动态规划(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 ...
随机推荐
- File system needs to be upgraded. You have version null and I want version 7
安装hbase时候报错: File system needs to be upgraded. You have version null and I want version 7 注: 我安装的hba ...
- ubuntu14.04利用aliyun安装docker
docker官网上的安装步骤比较麻烦,而且下载下来后pull镜像也特别慢.通过阿里云可以快速安装docker,并且可配置加速器.通过阿里云超快速安装docker: 安装或升级Docker 请安装1.6 ...
- css3动画特效:上下晃动的div
css3动画特效:上下晃动的div <div id="square" class="container animated">上下晃动</div ...
- C4.5,CART,randomforest的实践
#################################Weka-J48(C4.5)################################# ################### ...
- python——创建django项目全攻略(野生程序员到家养程序员的完美进化)
新建工程 我用pycharm写代码,所以一般就用pycharm创建django工程.右上角File-New Project.选择路径,修改项目名称,确定.就可以创建一个新的django工程. ...
- ant学习简单例子
1.下载ant,http://ant.apache.org/ 这个网站下载,然后配置环境变量 打开dos界面,输入ant -version,如果提示命令不存在,进入到ant包装目录bin下载,再次运行 ...
- 在iframe父界面获取iframe里面的标签
上一篇里边介绍了在里边利用iframe引入另一个html导航文件,有兴趣的朋友可以看一看 http://www.cnblogs.com/simba-lkj/p/6031662.html 目前遇到一些问 ...
- [HTML/HTML5]7 使用列表
7.1 在Web页面中使用有序.无序.定义列表 (1)有序列表 有序列表中的每一个列表项之前,都以一个数字或字母作为编号. <ol> <li>树莓</li> &l ...
- JSON的一些细节
这篇JSON的随笔只是为了简单地复习一下学习到的JSON的内容.都是一些很基础的东西.如果你不小心看到了这篇文,那就一起复习吧.(。・∀・)ノ JSON不支持JavaScript中的undefined ...
- iOS:使用代理模式监听开关状态改变事件
记一次解决跨控制器监听开关状态改变的尝试. 为了统一设置UITableViewCell里的内容,自定义了UITableViewCell类的一个基类,命名为SettingCell.SettingCell ...