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 ...
随机推荐
- POJ Challenge消失之物
Description ftiasch 有 N 个物品, 体积分别是 W1, W2, ..., WN. 由于她的疏忽, 第 i 个物品丢失了. "要使用剩下的 N - 1 物品装满容积为 x ...
- 转!!负载均衡器技术Nginx和F5的优缺点对比
对于数据流量过大的网络中,往往单一设备无法承担,需要多台设备进行数据分流,而负载均衡器就是用来将数据分流到多台设备的一个转发器. 目前有许多不同的负载均衡技术用以满足不同的应用需求,如软/硬件负载均衡 ...
- JQuery筛选器全系列介绍
jQuery提供了强大的选择器让我们获取对象.在这边,我人为地将jQuery选择器分为两大部分:选择对象和筛选条件.选择对象表示要获取什么对象,筛选条件是对获取的对象进行筛选,最终留下符合某些特征的对 ...
- iOS适配https详解
马上就要元旦了,网上流传元旦之后苹果会对所有的app进行https的验证,据说会拒绝所有没有使用https的app.但是后来又听说是我们开发者误解了,元旦过后还是会支持http,不过开发者需要说明为什 ...
- 20145224&20145238 《信息安全系统设计基础》 第三次实验
20145224&20145238 <信息安全系统设计基础>第三次实验 课程:信息安全系统设计基础 班级:1452 姓名:陈颢文 荆玉茗 学号:20145224 20145238 ...
- ionic实现双击返回键退出功能
实现这个功能需要四个步骤: 步骤一: 说明:因为需要和手机的硬件(返回按钮)打交道,而ionic本身是不具备该功能的,但是有一个东西可以:ng-cordova插件,这个插件是phoneGap为了能让i ...
- 自己建二维obj
经常用到啊 在项目流程管理里面用到
- 元素操作(sizing,尺寸获取,设值,偏移算法,坐标算法)
css3的Sizing Box-sizing是css3的box属性之一,遵循css的boxmodel原理,css中box model是分为两种,第一种是w3c的标准模型,另一种是ie的传统模型,他们相 ...
- VS2010开发AutoCAD 2012 .net应用程序调试时断点不起作用
VS2010+ AutoCAD 2012开发调试过程中,发现普通的Class里面的断点是可以跟踪到的,可能是创建自定义的Form做界面是,Form1.cs中的代码断点却不管用.原因在于AutoCAD的 ...
- 实战Nginx与PHP(FastCGI)的安装、配置与优化
一.什么是 FastCGIFastCGI是一个可伸缩地.高速地在HTTP server和动态脚本语言间通信的接口.多数流行的HTTP server都支持FastCGI,包括Apache.Nginx和l ...