CF-19B - Checkout Assistant(DP)
来源:互联网 发布:淘宝摄影产品拍照商家 编辑:程序博客网 时间:2024/05/20 23:59
Crawling in process...Crawling failedTime Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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 priceci and timeti 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 followingn lines each item is described by a pair of numbersti,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 itemi.
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
思路:简单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-19B - Checkout Assistant(DP)
- codeforces 19B - Checkout Assistant DP 背包
- CodeForces 19B Checkout Assistant dp
- CodeForces 19B Checkout Assistant
- CodeForces 19B Checkout Assistant (背包)
- codeforces 19B Checkout Assistant (背包)
- Codeforces Beta Round #19 B. Checkout Assistant CF19B
- cf 414B DP
- cf 264b dp
- CF 573B DP
- 【DP】 cf 487B
- CF - 294B DP
- CF - 375B DP
- cf19B. Checkout Assistant 【01 背包】
- CF 154 div2 B(dp)
- CF 2 B(dp)
- CF Div2 (220) B --- dp
- CF 429B (三维dp)
- 策略模式
- Handling the OnRequestStart and OnResponseEnd Client Events
- ant和Xdoclent生成配置文件
- C++: std::string 与 Unicode 如何结合?
- hrping版本早升级到V5.0.4了
- CF-19B - Checkout Assistant(DP)
- 嵌入式软件多机升级
- 创业公司webgame项目开发团队人员安排
- Hibernate常见异常总结(不断补充)
- Retrieving AjaxSettings on the Client
- umbraco学习5:Macros
- thrift源码研究-transport类体系研究总结
- linux学习笔记(4)-关于fcitx\SCIM以及ScribeFire
- ms sql server 查询一个表的字段属性和主键