




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
动态规划的技巧阶段的划分和状态的表示在动态规划的设计过程中,阶段的划分和状态的表示是非常重要的两步,这两步会直接影响该问题的计算复杂性,有时候阶段划分或状态表示的不合理还会使得动态规划法不适用。例9街道问题在下图中找出从左下角到右上角的最短路径,每步只能向右方或上方走。这是一道简单而又典型的动态规划题,许多介绍动态规划的书与文章中都拿它来做例子。通常,书上的解答是这样的:按照图中的虚线来划分阶段,即阶段变量k表示走过的步数,而状态变量xk表示当前处于这一阶段上的哪一点。这时的模型实际上已经转化成了一个特殊的多段图。用决策变量uk=0表示向右走,uk=1表示向上走,则状态转移方程如下:(这里的row是地图竖直方向的行数)我们看到,这个状态转移方程需要根据k的取值分两种情况讨论,显得非常麻烦。相应的,把它代入规划方程而付诸实现时,算法也很繁。因而我们在实现时,一般是不会这么做的,而代之以下面方法:(这里Distance表示相邻两点间的边长)这样做确实要比上面的方法简单多了,但是它已经破坏了动态规划的本来面目,而不存在明确的阶段特征了。如果说这种方法是以地图中的行(A、B、C、D)来划分阶段的话,那么它的状态转移就不全是在两个阶段之间进行的了。也许这没什么大不了的,因为实践比理论更有说服力。但是,如果我们把题目扩展一下:在地图中找出从左下角到右上角的两条路径,两条路径中的任何一条边都不能重叠,并且要求两条路径的总长度最短。这时,再用这种简单的方法就不太好办了。如果非得套用这种方法的话,则最优指标函数就需要有四维的下标,并且难以处理两条路径不能重叠的问题。而我们回到原先标准的动态规划法,就会发现这个问题很好解决,只需要加一维状态变量就成了。即用xk=(ak,bk)分别表示两条路径走到阶段k时所处的位置,相应的,决策变量也增加一维,用uk=(xk,yk)分别表示两条路径的行走方向。状态转移时将两条路径分别考虑在写规划方程时,只要对两条路径走到同一个点的情况稍微处理一下,减少可选的决策个数:从这个例子可以看出,合理地划分阶段和选择状态可以给解题带来方便。例10 LITTLE SHOP OF FLOWERS (IOI99)PROBLEMYou want to arrange the window of your flower shop in a most pleasant way. You haveFbunches of flowers, each being of a different kind, and at least as many vases ordered in a row. The vases are glued onto the shelf and are numbered consecutively 1 throughV, whereVis the number of vases, from left to right so that the vase 1 is the leftmost, and the vaseVis the rightmost vase. The bunches are moveable and are uniquely identified by integers between 1 andF. These id-numbers have a significance: They determine the required order of appearance of the flower bunches in the row of vases so that the bunchimust be in a vase to the left of the vase containing bunchjwheneverij. Suppose, for example, you have a bunch of azaleas (id-number=1), a bunch of begonias (id-number=2) and a bunch of carnations (id-number=3). Now, all the bunches must be put into the vases keeping their id-numbers in order. The bunch of azaleas must be in a vase to the left of begonias, and the bunch of begonias must be in a vase to the left of carnations. If there are more vases than bunches of flowers then the excess will be left empty. A vase can hold only one bunch of flowers.Each vase has a distinct characteristic (just like flowers do). Hence, putting a bunch of flowers in a vase results in a certain aesthetic value, expressed by an integer. The aesthetic values are presented in a table as shown below. Leaving a vase empty has an aesthetic value of 0.V A S E S12345Bunches1 (azaleas)723-5-24162 (begonias)521-410233 (carnations)-215-4-2020According to the table, azaleas, for example, would look great in vase 2, but they would look awful in vase 4.To achieve the most pleasant effect you have to maximize the sum of aesthetic values for the arrangement while keeping the required ordering of the flowers. If more than one arrangement has the maximal sum value, any one of them will be acceptable. You have to produce exactly one arrangement.ASSUMPTIONS 1 =F= 100 whereFis the number of the bunches of flowers. The bunches are numbered 1 throughF. F=V= 100 whereVis the number of vases. -50 =Aij= 50 whereAijis the aesthetic value obtained by putting the flower bunchiinto the vasej.INPUTThe input is a text file namedflower.inp. The first line contains two numbers:F,V. The followingFlines: Each of these lines containsVintegers, so thatAijis given as thejthnumber on the (i+1)stline of the input file.OUTPUTThe output must be a text file namedflower.outconsisting of two lines: The first line will contain the sum of aesthetic values for your arrangement. The second line must present the arrangement as a list ofFnumbers, so that thekth number on this line identifies the vase in which the bunchkis put.EXAMPLEflower.inp:3 57 23 -5 -24 165 21 -4 10 23-21 5 -4 -20 20flower.out:532 4 5EVALUATION Your program will be allowed to run 2 seconds. No partial credit can be obtained for a test case.本题虽然是IOI99中较为简单的一题,但其中大有文章可作。说它简单,是因为它有序,因此我们一眼便可看出这题应该用动态规划来解决。但是,如何动态规划呢?如何划分阶段,又如何选择状态呢?以花束的编号来划分阶段。在这里,第k阶段布置第k束花,共有F束花,有F+1个阶段,增加第F+1阶段是为了计算的方便;状态变量xk表示第k束花所在的花瓶。而对于每一个状态xk,决策uk就是第k+1束花放置的花瓶号;最优指标函数fk(xk)表示从第k束花到第n束花所得到的最大美学值;A(i,j)是花束i插在花瓶j中的美学值,V是花瓶总数,F是花的总数。状态转移方程为规划方程为边界条件为:,事实上这是一个虚拟的边界。最后要求的最大美学价值是方法1的规划方程中的允许决策空间:xk+1ukV-(F-k)+1 比较麻烦,因此有待改进。还是以花束的编号来划分阶段,第k阶段布置第k束花;状态变量xk表示第k束花所在的花瓶;注意,这里我们考虑倒过来布置花瓶,即从第F束花开始布置到第1束花。于是状态变量uk表示第k-1束花所在的花瓶;最优指标fk(xk)表示从第一束花到第k束花所获得的美学价值;A(i,j)是花束i插在花瓶j中的美学值,V是花瓶总数,F是花的总数。则状态转移方程为:规划方程为:增加的虚拟边界条件为:最后要求的最大美学价值是:可以看出,这种方法实质上和方法1没有区别,但是允许决策空间的表示变得简单了。以花瓶的数目来划分阶段,第k个阶段决定花瓶k中是否放花;状态变量xk表示前k个花瓶中放了多少花;而对于任意一个状态xk,决策就是第xk束花是否放在第k个花瓶中,用变量uk=1或0来表示。最优指标函数fk(xk)表示前k个花瓶中插了xk束花,所能取得的最大美学值。注意,这里仍然是倒过来考虑。状态转移方程为规划方程为边界条件为三种不同的方法都成功地解决了问题,只不过因为阶
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 IEC 60749-34-1:2025 EN-FR Semiconductor devices - Mechanical and climatic test methods - Part 34-1: Power cycling test for power semiconductor module
- 【正版授权】 IEC 60068-3-14:2025 FR Environmental testing – Part 3-14: Supporting documentation and guidance – Developing a climatic sequential test
- 校园超市消防知识培训内容课件
- 校园消防知识培训课件演练
- 校园消防知识培训内容课件
- 药师专业考试试题及答案
- 初级底盘考试题及答案
- 金桥劳务面试题及答案
- 中国古建筑考试试题及答案
- 淘宝处罚考试题及答案
- 2025矿山承包合同范文
- 人教版(2024)数学七年级上册期末测试卷(含答案)
- 数字化数据中台技术方案
- 锁骨骨折的护理课件
- 《物业管理法规》课件
- 2024华为干部管理资料第7版
- 《复活》(节选)列夫托尔斯泰-精讲课件
- (完整版)投标文件范本(格式)
- 中国风肺胀中医护理方案
- GB/T 10433-2024紧固件电弧螺柱焊用螺柱和瓷环
- 2024年样板注塑机转让合同范本
评论
0/150
提交评论