CF19B 01背包(必须装满)
来源:互联网 发布:淘宝如何加入天猫 编辑:程序博客网 时间:2024/04/30 22:12
http://codeforces.com/problemset/problem/19/B
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.
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 one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.
42 100 201 51 3
8
30 10 100 100
111
/**cf19B题意:一个人想在超市偷东西...1秒偷一件,问偷过之后最后付的最少的钱是多少做法:就是买N件物品化最少的钱,以前是买一件物品可以得到一件,因为现在可以偷,可以认为是买一件物品送t件。背包必须完全装满,初始化注意*/#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;LL f[2005];int n;int main(){ while(~scanf("%d",&n)) { LL x,y; ///背包必须装满,初始化除了f[0]其余全为无穷 memset(f,0x3f3f3f3f3f,sizeof(f)); f[0]=0; for(int i=1;i<=n;i++) { scanf("%I64d%I64d",&x,&y); x++; for(int j=n;j>=0;j--) { if(j>=x) f[j]=min(f[j],f[j-x]+y); else f[j]=min(f[j],y); } } printf("%I64d\n",f[n]); } return 0;}
- CF19B 01背包(必须装满)
- CF19b: Checkout Assistant(类01背包)
- cf19B. Checkout Assistant 【01 背包】
- HDU 1114 又见完全背包问题(必须装满)
- hdu 1114 Piggy-Bank(必须装满的完全背包)
- 01背包(要求恰好装满)
- 01背包装满
- 完全背包(装满)模板
- 01背包,恰好装满(劲歌金曲,uva 12563)
- 01背包中是否背包装满问题
- 01背包中是否背包装满问题
- cf19B Checkout Assistant (01背包_好题)
- codeforce 189A 完全背包之必须装满问题
- 01背包 装满 hdu 1079 The Balance
- soj 3172 Fisherman (01背包的装满)
- hdu1114(完全背包+恰好装满)
- 装满01背包问题和01背包问题
- NYOJ 题目311 完全背包(完全背包,装满)
- 136 single number
- 使用SetUnhandledExceptionFilter转储程序崩溃时内存DMP
- file各种操作
- EJB到底是什么,真的那么神秘吗??
- 傻瓜式编译ffmpeg
- CF19B 01背包(必须装满)
- Android手势检测技术(一)
- 为什么我发的每条都要审核
- 一线架构师实践指南读书笔记
- Halcon PDF文档(hdevelop_users_guide)学习总结之四——关于3D显示模式
- 关于c#中的Func<>和Action<>
- mars android开发之九:Content Provider
- CSS3+SVG 响应式图标设计
- PHPCMS V9上传附件图片出现“服务器安全认证错误”解决方法