CodeForces 19B Checkout Assistant
1 second
256 megabytes
standard input
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 priceci 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.
4
2 10
0 20
1 5
1 3
8
3
0 1
0 10
0 100
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]);
}
else
dp[j]=min(dp[j],a[i][1]);
}
}
printf("%lld\n",dp[n]);
return 0;
}
CodeForces 19B Checkout Assistant的更多相关文章
- Checkout Assistant CodeForces - 19B
题意: 给你n个物品,每个物品有一个价格ci和一个支付时间ti,在这个ti时间内,你可以免费拿ti个物品.问你想要带走这n个物品最小需要多少钱 题解: 原本还想着贪心去写,但是好像贪心写不了,,,不属 ...
- B. Checkout Assistant 01背包变形
http://codeforces.com/problemset/problem/19/B 对于每个物品,能偷多ti个,那么先让ti + 1, 表示选了这个东西后,其实就是选了ti + 1个了.那么只 ...
- [CF19B]Checkout Assistant
题目描述 Bob 来到一家现购自运商店,将 n 件商品放入了他的手推车,然后到收银台 付款.每件商品由它的价格 pi 和收银员扫描它的时间 ti 秒定义.当收银员正在扫 描某件商品时,Bob 可以从他 ...
- Codeforces Beta Round #19
A. World Football Cup #include <bits/stdc++.h> using namespace std; ; char name[N][N]; map&l ...
- CF dp 题(1500-2000难度)
前言 从后往前刷 update 新增 \(\text{\color{red}{Mark}}\) 标记功能,有一定难度的题标记为 \(\text{\color{red}{红}}\) 色. 题单 (刷过的 ...
- codeforces 377A. Puzzles 水题
A. Puzzles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/33 ...
- Codeforces Round #415 (Div. 2)(A,暴力,B,贪心,排序)
A. Straight «A» time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
- Codeforces Round#415 Div.2
A. Straight «A» 题面 Noora is a student of one famous high school. It's her final year in school - she ...
- CodeForces 337A Puzzles
Puzzles Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origina ...
随机推荐
- 常用命令——sed详解
以下内容参考:http://qifuguang.me/2015/09/21/sed命令详解/ sed是stream editor的简称,也就是流编辑器.它一次处理一行内容,处理时,把当前处理的行存储在 ...
- 第二百九十二节,RabbitMQ多设备消息队列-Python开发
RabbitMQ多设备消息队列-Python开发 首先安装Python开发连接RabbitMQ的API,pika模块 pika模块为第三方模块 对于RabbitMQ来说,生产和消费不再针对内存里的一 ...
- 类的数据成员加前缀 m_(表示 member)
类的数据成员加前缀 m_(表示 member),这样可以避免数据成员与 成员函数的参数同名. 例如: void Object::SetValue(int width, int height) { m_ ...
- motion的移植和使用
说明: motion主页:http://www.lavrsen.dk/foswiki/bin/view/Motion motion下载地址:http://sourceforge.net/project ...
- CentOS安装Emacs文本编辑器
我这里安装的是:emacs.24.2 下载地址:http://ftp.gnu.org/pub/gnu/emacs/emacs-24.2.tar.gz 下载文件:emacs-24.2.tar.gz 步骤 ...
- 同一种类型的两个对象赋值,用反射。再也不用点属性了。。。。(适用于ef)
/// <summary> /// 给对象赋值的方法(不赋地址)(同一个类型),含过滤 /// </summary> /// <typeparam name=" ...
- App 应用通过网页打开 App Store
NSURL *url = nil; if ([[[UIDevice currentDevice] systemVersion] intValue] >= 7.0) { //iOS7 使用旧的网址 ...
- make的自动变量和预定义变量
make的自动变量 $@ 规则目标的文件名.如果目标是档案文件的一个成员,"$@"就是档案文件的名称 $% 当目标是档案文件的一个成员时,"$%"是该成员的名称 ...
- [转]wcout输出中文却不显示出来
准备使用UNICODE来写个控制台测试程序发现,cout无法输出UNICODE的中文字符.查找C++标准看到,其提供了wcin.wcout.wcerr.wclog用于处理wchar_t字符的输入输出. ...
- UI设计要学哪些软件
准备做UI设计的或是已经在做UI设计的童鞋,哪些软件是我们要学习的重点,作者把UI设计分成了好几个不同的职业方向,从事什么UI设计方向,就学什么软件,这样针对性就很强了,无论怎么说,Photoshop ...