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 ...
随机推荐
- e558. 在Applet中多图片交互显示
This is the simplest applet to animate an array of images. In practice, you should use double-buffer ...
- linux -- 查看Ubuntu命令行调用的文件
which 如: 输入:which reboot 输出:/sbin/reboot 输入:which shutdown -h now 输出:/sbin/shutdown
- Qt的窗口的最大化。
1.window.showFullScreen()//此方法只对顶级窗口有效,对子窗口无效 QT中窗口部件QWidget成员函数showFullScreen();是用于将窗口部件全屏显示,但是他只对窗 ...
- win7在64位系统下编译openssl
曾经在笔记本上配置过openssl-0.9.8g版本号,今天在公司的台式机上配置死活没配置成功.机器的系统是win7,64位.编译openssl-1.0.1e出现各种莫名的错误,最后无意中编译了1.0 ...
- mybatis传递Map和List集合示例
1.List示例 java文件: dao: public List<ServicePort> selectByIps(List<String> ips); xml文件: < ...
- 【java】java内存模型 (1)--基础
并发编程模型的分类 在并发编程中,我们需要处理两个关键问题:线程之间如何通信及线程之间如何同步(这里的线程是指并发执行的活动实体).通信是指线程之间以何种机制来交换信息.在命令式编程中,线程之间的通信 ...
- [转]ASP.NET MVC 5– 使用Wijmo MVC 5模板1分钟创建应用
开始使用 使用ComponentOne Studio for ASP.NET Wijmo制作MVC5应用程序,首先要做的是安装Studio for ASP.NET Wijmo . 测试环境 VS201 ...
- oracle_存储过程_没有参数_根据配置自动创建申请单以及写日志事务回滚
CREATE OR REPLACE PROCEDURE A_MEAS_MIINSP_PLAN_CREATEASvs_msg VARCHAR2(4000);p_PERIODTYPE number; -- ...
- 件测试专家分享III GUI自动化测试相关
GUI自动化:效率为王—脚本与数据解偶 页面对象模型的核心理念是,以页面(Web Page或者Native App Page)为单位来封装页面上的空间以及控件部分操作. 而测试用力,更确切的说是操作函 ...
- DAGDGC特殊调弦
DAGDGC 特殊调弦 重要知识点: 1)音高从高到低排序为:BAGFEDC 2)吉他标准音是(1到6弦) EBGDAE 3)吉他同一弦,每相差一个品级,相差是半个音 调弦方法:1)第一弦(E-> ...