2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 D. Hack Portals(区间DP)

185 篇文章 0 订阅
96 篇文章 0 订阅

We all have much to be proud of.

As a player of the game Ingress, IloveMATH is proud of these portals on the road in front of his campus.

Here is a brief introduction of this mobile game. Ingress, as a sandbox game, connects the actual world around us with the virtual battleground.

Those strategic fortress points, we call portals, correspond to the real buildings, sculptures, statues and other objects that can easily be discoverd.

If you read the virtual map of the Ingress world, a neat row of portals along the road in front of Xtended Domain University (XDU) could catch your eye immediately.

The total length of the road is LLL metres, and there are NNN portals on the road.

The distance between the left side of the road and the iii-th portal is XiX_iXi, where 0≤Xi≤L0\le X_i\le L0XiL and XiX_iXi is an integer.

The gate of XDU is situated on KKK, where KKK is an integr and 0≤K≤L0\le K\le L0KL as well.

To get more virtual supplies and properties in the game, IloveMATH should hack these portals.

Hacking a portal can get some items randomly such as missiles, shields and turrets.

However, hacking would heat the portal and the player could not hack it again until the portal finished the process of cooling.

Now IloveMATH stands at the left side of the road (located on 000).

He knows the end time of cooling for each portal.

His mission is to visit and hack each portal at least once and go back to the school gate.

The time consumption of moving from iii to jjj is ∣i−j∣|i-j|ij and the hacking is instantaneous (its time consumption is 000).

Help IloveMATH finish the mission as soon as possible. It's time to move.

Input Format

The input of this problem contains several test cases.

The first line of the input provides the total number of test cases.

Each test case is consists of N+1N+1N+1 lines and the first lines provides three integers N (N≤1000)N~(N\le 1000)N (N1000), L (L≤1000)L~(L\le 1000)L (L1000) and K (0≤K≤L)K~(0\le K\le L)K (0KL).

The following NNN lines correspond to NNN portals and the iii-th line contains the location of the portal, and its end time of cooling.

All input numbers should be small than 327683276832768.

Output Format

For each test case output the case number first. Then output the best time for completing the mission.

样例输入
1

4 10 3
8 9
4 21
3 16
8 12
样例输出
Case #1: 22
题目来源

2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛


题意: 数轴上有n个点,每个点都在一个特定的时间后出现,你现在的位置在0,问把所有点都访问一次最后走到k的最少时间.


分析:手动画几个例子,可以发现最优解的每个状态中未被hack的po一定是一段连续的区间,于是可以直接上二维区间dp,f[i][j][k]表示[i,j]这段区间之外的都hack后停留在k(左/右)端的最少时间,然后就可以O(1)转移了,总复杂度O(n^2).



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值