您当前的位置: 首页 > 

HeartFireY

暂无认证

  • 4浏览

    0关注

    334博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

HDU-2829 Lawrence 斜率优化DP 题解与分析

HeartFireY 发布时间:2021-01-25 20:07:59 ,浏览量:4

● 本题解会有详细的分析,适合初学者阅读 ⚠ 超长题目分析警告 原题

Problem Description

T. E. Lawrence was a controversial figure during World War I. He was a British officer who served in the Arabian theater and led a group of Arab nationals in guerilla strikes against the Ottoman Empire. His primary targets were the railroads. A highly fictionalized version of his exploits was presented in the blockbuster movie, “Lawrence of Arabia”.

You are to write a program to help Lawrence figure out how to best use his limited resources. You have some information from British Intelligence. First, the rail line is completely linear—there are no branches, no spurs. Next, British Intelligence has assigned a Strategic Importance to each depot—an integer from 1 to 5. A depot is of no use on its own, it only has value if it is connected to other depots. The Strategic Value of the entire railroad is calculated by adding up the products of the Strategic Values for every pair of depots that are connected, directly or indirectly, by the rail line. Consider this railroad:

img Its Strategic Value is 45 + 41 + 42 + 51 + 52 + 12 = 49. Now, suppose that Lawrence only has enough resources for one attack. He cannot attack the depots themselves—they are too well defended. He must attack the rail line between depots, in the middle of the desert. Consider what would happen if Lawrence attacked this rail line right in the middle:

img The Strategic Value of the remaining railroad is 45 + 12 = 22. But, suppose Lawrence attacks between the 4 and 5 depots:

img The Strategic Value of the remaining railroad is 51 + 52 + 1*2 = 17. This is Lawrence’s best option.

Given a description of a railroad and the number of attacks that Lawrence can perform, figure out the smallest Strategic Value that he can achieve for that railroad.

Input

There will be several data sets. Each data set will begin with a line with two integers, n and m. n is the number of depots on the railroad (1≤n≤1000), and m is the number of attacks Lawrence has resources for (0≤m> m, n + m){ memset(cost, 0, sizeof(cost)), cnt[0] = 0; for (rnt i = 1; i > val[i]; for (rnt i = 1; i

关注
打赏
1662600635
查看更多评论
立即登录/注册

微信扫码登录

0.0452s