- 1、本文档共11页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
搬寝室
Dynamic Programming
---moving into a new dormitory
Problem
Question
Can you find the optimal solution to the lowest sense of tiring to help the poor Mary?
n is the total number of her baggage
2*k is the number of baggage she will move.
(2=2*k=n2000)
w[i] is the weight of the No.i baggage;
dp[i][j] is the lowest sense of tiring when moving 2*i pieces of baggage from j pieces of baggage.
DP Step 1: characterizing the optimal sub-structure
Moving into a new dormitory problem has the optimal sub-structure.
The optimal solution for the lowest sense of tiring is dp[k][n]
If we move the No.n baggage,the lowest sense of tiring dp[k-1][n-2] should also be optimal; or else we can replace the non-optimal solution with an optimal one
If we don’t move the No.n baggage,the lowest sense of tiring dp[k][n-1](= dp[k][n] )should also be optimal; or else we can replace this non-optimal solution with an optimal one
DP Step 2: construct the recursion solution
Case 1: We do not move No.j baggage.
– We select best 2*i pieces from { 1, 2, …, j-1 }
Case 2: We move No.j baggage.
–If we move j ,we must move j-1,as we should move a pair of baggage.
– We select best 2*(i-1) pieces from { 1, 2, …, j-2 }
Assuming k=1
when n=2,there is only one choice,that is,moving w[1] and w[2] together.So dp[1][2]=(w[1]-w[2])^2.
when n=3,there are two choices,that is,w[1],w[2]or w[2],w[3].So dp[1][3]=min{dp[1][2],dp[0][1]+(w[2]-w[3])^2}
Assuming k=2
when n=4,there is only one choice,that is ,moving w[1], w[2] together and moving w[3],w[4] together.So dp[2][4]=(w[1]-w[2])^2+(w[3]-w[4])^2.
when n=5,dp[2][5]=min{dp[2][4],dp[1][3]+(w[4]-w[5])^2}.
……
Code
input k,n, w[1],….w[n];
Make an array dp[0][0],….,dp[k][n] ;
for i=0 to n
dp[0][i]=0;
sort(w);
for i=1 to k
{
dp[i][i+i]=dp[i-1][i+i-2]+(w[i+i-1]-w[i+i])*(w[i+i-1]-w[i+i]);
for j=2*i+1 to n
dp[i][j]=min(dp[i][j-1],dp[i-1][j-2]+(w[j]-w[j-1])*(w[j]-w[j-1
您可能关注的文档
- 东城区2010年4月一模理科数学试卷(含答案).doc
- 专题课.ppt
- 主板CPU供电电路详解.doc
- 上海热线介绍PPT.ppt
- 九年级上数学测试.doc
- 九年级英语试卷(9BUnit1-2).doc
- 九年级物理___课件.ppt
- 付桥小学师德师风建设措施.doc
- 五年级数学进度表.doc
- 儿童学习弹奏钢琴有什么好处.doc
- 2024年长春市公务员考试行测试卷历年真题及一套完整答案详解.docx
- 2024年省直辖行政单位公务员考试行测真题及答案详解1套.docx
- 2024年淄博市公务员考试行测真题及1套完整答案详解.docx
- 2024年苏州市公务员考试行测试卷历年真题及1套参考答案详解.docx
- 2024年蚌埠市公务员考试行测真题及答案详解(新).docx
- 2024年盐城市公务员考试行测试卷历年真题精选答案详解.docx
- 2024年衡水市公务员考试行测试卷历年真题精编答案详解.docx
- 2024年连江县公务员考试行测真题及答案详解(全优).docx
- 2024年白城市公务员考试行测试卷历年真题及一套答案详解.docx
- 2024年铜川市公务员考试行测真题及答案详解(有一套).docx
文档评论(0)