CF-19B - Checkout Assistant(DP)
2013-01-23 21:58
381 查看
B - Checkout Assistant
Crawling in process...Crawling failedTime
Limit:2000MS Memory Limit:262144KB
64bit IO Format:%I64d & %I64u
SubmitStatusPracticeCodeForces
19B
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
Output
Input
Output
思路:简单01背包,不过要注意优化,就是题目中有说偷的时间只要1秒,所以当时间大于n秒时,他可以都所以物品,因此只要更新到 n就可以得到正确答案了。
仔细想想,记忆化搜索好像也行。
Crawling in process...Crawling failedTime
Limit:2000MS Memory Limit:262144KB
64bit IO Format:%I64d & %I64u
SubmitStatusPracticeCodeForces
19B
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
4 2 10 0 20 1 5 1 3
Output
8
Input
3 0 1 0 10 0 100
Output
111
思路:简单01背包,不过要注意优化,就是题目中有说偷的时间只要1秒,所以当时间大于n秒时,他可以都所以物品,因此只要更新到 n就可以得到正确答案了。
仔细想想,记忆化搜索好像也行。
#include<iostream> #include<algorithm> #include<cstring> #include<map> using namespace std; const long long oo=1e18; const int mm=2005; long long f[mm]; int m,x; long long y,z; int main() { while(cin>>m) { f[0]=0; for(int i=1;i<mm;i++) f[i]=oo; for(int i=0;i<m;i++) {cin>>x>>y; int mid; for(int j=m;j>=0;j--) { if(j+x+1<m)mid=j+x+1;///时间大于m时,他可以偷所有物品因此只需到m就行 else mid=m; if(f[j]+y<f[mid])///更新值 f[mid]=f[j]+y; } } cout<<f[m]<<"\n"; } }
相关文章推荐
- 【转】cf 825F - 19 String Compression 【kmp+dp】
- CF Educational Round 19 797 (F题DP+RMQ)以后补
- CF-19B - Checkout Assistant(DP)
- CF 461B Appleman and Tree (树形dp)
- CF 2 B(dp)
- CF 148D Bag of mice (概率DP)
- CF:358C 暴力DP筛选素数预处理
- 【CF 724E】Goods transportation(最小割+DP)
- CF 455A(Boredom-dp)
- cf 815C Karen and Supermarket 树形dp
- CF 161D Distance in Tree 树形DP
- CF_D. Choosing Capital for Treeland_树形DP
- CF#(4D)Mysterious Present(DP)
- CF 149D Coloring Brackets(区间DP,好题,给配对的括号上色,求上色方案数,限制条件多,dp四维)
- CF 295C Greg and Friends DP
- CF 55D - Beautiful numbers(数位DP)
- CF 311B Cats Transport(单调队列优化DP)
- CF(D. Fibonacci Sums)dp计数
- CF 366C。。。 鏖战了一晚上了 一道要换换角度的DP
- CF 327E(Axis Walking-状态压缩Dp-lowbit的使用)