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的更多相关文章

  1. 动态规划 Dynamic Programming

    March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...

  2. HDU 4223 Dynamic Programming?(最小连续子序列和的绝对值O(NlogN))

    传送门 Description Dynamic Programming, short for DP, is the favorite of iSea. It is a method for solvi ...

  3. hdu 4223 Dynamic Programming?

    Dynamic Programming? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  4. 算法导论学习-Dynamic Programming

    转载自:http://blog.csdn.net/speedme/article/details/24231197 1. 什么是动态规划 ------------------------------- ...

  5. Dynamic Programming: From novice to advanced

    作者:Dumitru 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProg An impo ...

  6. HDU-4972 A simple dynamic programming problem

    http://acm.hdu.edu.cn/showproblem.php?pid=4972 ++和+1还是有区别的,不可大意. A simple dynamic programming proble ...

  7. [算法]动态规划(Dynamic programming)

    转载请注明原创:http://www.cnblogs.com/StartoverX/p/4603173.html Dynamic Programming的Programming指的不是程序而是一种表格 ...

  8. hdu 4972 A simple dynamic programming problem(高效)

    pid=4972" target="_blank" style="">题目链接:hdu 4972 A simple dynamic progra ...

  9. 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 ...

随机推荐

  1. 【Java】异常处理_学习笔记

    异常: 1.格式1: try { //业务代码 } catch(Exception e) { //异常处理代码 } 说明: a.   异常抛出:执行try里的代码,系统会自动生成一个异常对象,该对象会 ...

  2. OpenCV 计算区域的内部参数

    对于一个区域,怎么进一步针对区域内部特征进行处理呢 ? 首先,我们要提取出来内部的某些特征才能说话,下面提取一些简单的特征,话不多说见代码: 1.平均数及方差参数: Mat tempMean, tem ...

  3. Unity学习笔记

    『 知识点』 [射线] 射线检测碰撞 『游戏实战』 个例 [E]<愤怒的小鸟> 资源 免费Unity基础教程(中文电子书) [E] noobtus(Unity游戏教程)

  4. 补PSP进度(10.28-11.3)

    本周PSP进度 10月31号 内容 开始时间 结束时间 打断时间 净时间 看蛋白质相互作用论文 8:40 10:35 约12m 103m 分析约跑功能 13:20 13:55 0 35m 练习VSL2 ...

  5. 深入浅出Mybatis系列(五)---TypeHandler简介及配置(mybatis源码篇)

    上篇文章<深入浅出Mybatis系列(四)---配置详解之typeAliases别名(mybatis源码篇)>为大家介绍了mybatis中别名的使用,以及其源码.本篇将为大家介绍TypeH ...

  6. ListView 的使用

    一.ListView:不同视图中一种显示想的集合,显示表格样式的数据信息1.视图:            在其右上方小箭头点击将视图改为Details:或者右键属性在外观View将其改为Details ...

  7. Ubuntu无法识别显示器情况下,高分辨率的设置

    安装ubuntu后,出现无法识别显示器,从而造成无法设置高分辨率. 界面显示似老年机般,5.3的视力+强迫症,臣妾的内心是十分拒绝的,捣鼓了半天终于搞定,这里记录下方法. (一)使用xrandr命令, ...

  8. jmeter

    Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测试但后来扩展到其他测试领域. 它可以用于测试静态和动态资源例如静态文件. ...

  9. Linux 批量修改文件名

    背景:在研究MP4解码播放的时候音视频字幕的分片命名不符合规范,分片个数太多只能脚本实现. 解决问题类型: 1.将Garfield1HD_261_dan-*.m4s 统一转换为Garfield1HD_ ...

  10. Angular js 之一些简单的js操作

    1.<div ng-if()> </div> 括号里面是布尔值  如果是false那么你ng-if的那个dom就会不显示.(感觉这是angular js中最给力的一点) 一般会 ...