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
42 100 201 51 3
8
30 10 100 100
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;}
- CodeForces 19BCheckout Assistant
- CodeForces 19B Checkout Assistant
- codeforces 19B - Checkout Assistant DP 背包
- CodeForces 19B Checkout Assistant (背包)
- CodeForces 19B Checkout Assistant dp
- codeforces 19B Checkout Assistant (背包)
- Codeforces Beta Round #19 B. Checkout Assistant CF19B
- CF-19B - Checkout Assistant(DP)
- ShareWare.Assistant
- SQL Assistant
- Mobile Assistant
- weather assistant
- accounting assistant
- Diary assistant
- .net assistant tools collection
- DataBase Configuration Assistant
- Intelligent Software Assistant
- SQL Assistant License key
- 练习001-002
- 求职宝典 第三章 结构体 共用体 与枚举
- Android Studio 配置NDK,运行第一个hello-jni安卓程序详细步骤
- Codeforces 645C 二分
- mysql_store_result和mysql_use_result
- CodeForces 19BCheckout Assistant
- 阿里一面(3.23)
- apt-get
- SGU195
- 三月份学习总结与读后感
- 重做日志与归档日志工作原理
- 1002. 写出这个数 (20)
- CodeForces 19D Points
- UVA 548(DFS)+二叉树遍历