CodeForces 19B Checkout Assistant
2016-04-04 16:59
330 查看
B. Checkout Assistanttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described byits priceci andtime ti inseconds 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 willhave to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.InputThe 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 is0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.OutputOutput one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.Examplesinput
4 2 10 0 20 1 5 1 3output
8input
3 0 1 0 10 0 100output
111
简单01背包,每个物品的付钱时间可以当作是买了这个物品还可以送你多少个物品。物品的数量相当于背包的体积,物品的价值相当于价值,问题就变成求背包体积大于等于n时,可以得到的最小价值
#include <iostream>#include <string.h>#include <stdlib.h>#include <algorithm>#include <stdio.h>#include <math.h>using namespace std;const long long int MAX=(long long int)1<<62;long long int dp[2005];long long int a[2005][2];int n;int main(){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%lld%lld",&a[i][0],&a[i][1]),a[i][0]++;for(int i=0;i<=n;i++)dp[i]=MAX;dp[0]=0;for(int i=1;i<=n;i++){for(int j=n;j>=0;j--){if(j>=a[i][0]){dp[j]=min(dp[j],dp[j-a[i][0]]+a[i][1]);}elsedp[j]=min(dp[j],a[i][1]);}}printf("%lld\n",dp);return 0;}
相关文章推荐
- Error Downloading Packages:
- 杭电2717
- 合并两个文件
- 码农小汪-Hibernate学习8-hibernate关联关系注解表示@OneToMany mappedBy @ManyToMany @JoinTable
- 【BZOJ-1406】密码箱 约数 + 乱搞 + set?
- CodeForces 19B Checkout Assistant
- 抽象工厂模式
- 第一篇博客 测试
- Light OJ 1223 Testing Mailboxes (DP)
- Android基础部分再学习---activity的生命周期
- 根据主机名获取IP地址
- 深入理解java中的synchronized关键字
- java 数字证书生成及证书的加密解密
- iOS开发之数据库Sqlite
- 在JS中关于堆与栈的认识function abc(a){ a=100; } function abc2(arr){ arr[0]=0; }
- 10014---Trail ~ CronJobs
- Mtalab统计信息处理的一些原理
- 个十百的应用实例
- Struts2 validation 错误信息重复不消失的问题
- 杭电acm阶段之理工大版