题目地址:https://codeforces.com/contest/1106/problem/E
Lunar New Year is approaching, and Bob is going to receive some red envelopes with countless money! But collecting money from red envelopes is a time-consuming process itself.
Let’s describe this problem in a mathematical way. Consider a timeline from time 1 to n. The i-th red envelope will be available from time si to ti, inclusive, and contain wi coins. If Bob chooses to collect the coins in the i-th red envelope, he can do it only in an integer point of time between si and ti, inclusive, and he can’t collect any more envelopes until time di (inclusive) after that. Here si≤ti≤di holds.
Bob is a greedy man, he collects coins greedily — whenever he can collect coins at some integer time x, he collects the available red envelope with the maximum number of coins. If there are multiple envelopes with the same maximum number of coins, Bob would choose the one whose parameter d is the largest. If there are still multiple choices, Bob will choose one from them randomly.
However, Alice — his daughter — doesn’t want her father to get too many coins. She could disturb Bob at no more than m integer time moments. If Alice decides to disturb Bob at time x, he could not do anything at time x and resumes his usual strategy at the time x+1 (inclusive), which may lead to missing some red envelopes.
Calculate the minimum number of coins Bob would get if Alice disturbs him optimally.
Description
在时间线为 1~n 上有 k 个信封和 m 个干扰机会,每个信封有领取时间段 [s, t]、时间点 d(领了个这个信封之后,在 d 点前无法领取其他信封)、以及价值 w,对于每个干扰机会,可以使其在任意一个时间点无法进行领取操作直到x+1。
问最优使用不超过m次干扰下,将领取的最小信封价值总和。每次领取的策略是取当前可领取信封中 w 最大的,w 相同时取 d 最大的。
Solution
dp[i][j] 表示前 i 个时间点中用了 j 次机会所能得到的最少金币。
由于Bob每次要优先取 wi 最大,其次是取 di 最大,所以利用优先队列,在当前 i 这个时间点,将所有满足条件的信封放入优先队列,然后再进行转移。
对于每个时间点 i,如果当前没有满足条件的信封即优先队列为空时,就要把当前时间点的状态保留至下一个时间点。
$for(int j = 0; j <= m; j++) dp[i+1][j] = Min(dp[i+1][j], dp[i][j]);$
如果有可用的信封,那么对于每次干扰机会 j,都有选择干扰和不干扰两种操作。
如果不干扰:$dp[di+1][j] = min(dp[di+1][j], dp[i][j] + wi);$
如果干扰:$dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j])$(注意此时 j 必须小与 m)
Code
1 |
|