博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF19b: Checkout Assistant(类01背包)
阅读量:6956 次
发布时间:2019-06-27

本文共 1988 字,大约阅读时间需要 6 分钟。

B. Checkout Assistant
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 tici(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.

Examples
input
42 100 201 51 3
output
8
input
30 10 100 100
output
111
题意:买N件商品,每件商品有收钱时间ti,价格ci,收钱时可以偷窃其他ti件商品,求带走这N件商品需要支付的最小费用。

思路:可以理解为花ci的钱能得到ti+1件商品,于是用01背包做法dp[i]表示在这N件商品中带走i件支付的最小费用dp[i] = min( dp[i], dp[i-(ti+1)] + ci )。

http://blog.csdn.net/lvshubao1314/article/details/42505443

# include 
# include
# include
using namespace std;int main(){ long long dp[2001], n, i, j, x, y; while(~scanf("%I64d",&n)) { memset(dp, 0x3f3f3f3f, sizeof(dp)); dp[0] = 0; for(i=1; i<=n; ++i) { scanf("%I64d%I64d",&x, &y); ++x; for(j=n; j>=x; --j) dp[j] = min(dp[j], dp[j-x]+y); for(; j>0; --j) //这里表示当前物品数小于第i件物品的ti时,收费第i件物品时能偷走完j件。 dp[j] = min(dp[j], y); } printf("%I64d\n",dp[n]); } return 0;}

转载于:https://www.cnblogs.com/junior19/p/6730073.html

你可能感兴趣的文章
P2495 [SDOI2011]消耗战
查看>>
P2633 Count on a tree
查看>>
重读<软件性能测试>摘要
查看>>
毕业季
查看>>
测评报告:热门项目管理工具哪家强?
查看>>
java.sql.SQLSyntaxErrorException: ORA-00904: " ": invalid identifier错误
查看>>
vue2.0做移动端开发用到的相关插件和经验总结
查看>>
Linux查看文件夹大小
查看>>
系统集成项目管理工程师整理资料
查看>>
writexml方法:
查看>>
AutoLayout经常用到的一些布局(含StackView)
查看>>
HLG 1541 集合划分【01背包】
查看>>
Java IO 详解
查看>>
php生成随机密码的几种方法
查看>>
c#编程模仿的1stopt界面
查看>>
Castle ActiveRecord的一对多问题
查看>>
移山亦可有道 ——读《移山之道》
查看>>
python使用windows注册表
查看>>
MySQL5.6.13安装步骤(Windows7 64位)札记 1
查看>>
使用 nginx + thin 的配置启动 rails server
查看>>