CodeForces 19BCheckout Assistant

来源:互联网 发布:亿网科技域名 编辑:程序博客网 时间:2024/06/05 06:18

Description

Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.

Input

The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti,ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.

Output

Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.

Sample Input

Input
42 100 201 51 3
Output
8
Input
30 10 100 100
Output

111

背包问题,把每一个t[i]加个1,问题转换为和大于等于n的最小花费。

#include<cmath>#include<queue>#include<stack>#include<vector>#include<cstdio>#include<bitset>#include<cstring>#include<iostream>#include<algorithm>#include<functional>using namespace std;typedef long long LL;const LL INF = (LL)1 << 61;const int low(int x){ return x&-x; }const int mod = 51123987;const int maxn = 5e3 + 10;int n, t[maxn], c[maxn];LL dp[maxn];int main(){while (~scanf("%d",&n)){dp[0] = 0;for (int i = 1; i <= n; i++){scanf("%d%d", &t[i], &c[i]);t[i]++;dp[i] = INF;}for (int i = 1; i <= n; i++){for (int j = n; j >= 0; j--){if (j < t[i]) dp[j] = min(dp[j], (LL)c[i]);else dp[j] = min(dp[j], dp[j - t[i]] + c[i]);}}cout << dp[n] << endl;}return 0;}


0 0
原创粉丝点击