题意:

给你n个物品,每个物品有一个价格ci和一个支付时间ti,在这个ti时间内,你可以免费拿ti个物品。问你想要带走这n个物品最小需要多少钱

题解:

原本还想着贪心去写,但是好像贪心写不了,,,不属于贪心
 
因为题目上说了要求把n个商品都买下所付出的最小的钱
因为买了第i件商品可以免费拿出来ti个,可以相当于一共拿出来ti+1个
那么这就相当于01背包了,n当作背包体积。但是要注意,如果背包剩余空间不够当前操作导致无法求出最优解呢?
所以背包剩余体积就算不够也可以放进去(具体见代码)
 
 
代码:
 1 #include<stdio.h>
2 #include<string.h>
3 #include<iostream>
4 #include<algorithm>
5 #include<queue>
6 #include<map>
7 #include<vector>
8 #include<math.h>
9 #define mem(a,x) memset(a,x,sizeof(a))
10 using namespace std;
11 typedef long long ll;
12 const int maxn=2000+10;
13 const int mod=26;
14 const int INF=0x3f3f3f3f;
15 const int Times = 10;
16 const int N = 5500;
17 const long long int MAX=(long long int)1<<62;
18 ll dp[maxn];
19 struct shudui
20 {
21 ll t,c;
22 }m[maxn];
23 int main()
24 {
25 ll n;
26 scanf("%I64d",&n);
27 for(ll i=0;i<n;++i)
28 {
29 scanf("%I64d%I64d",&m[i].t,&m[i].c);
30 m[i].t+=1;
31 }
32 for(int i=0;i<=n;++i)
33 dp[i]=MAX; //这里要用MAX而不能用INF
34 dp[0]=0;
35 for(ll i=0;i<n;++i)
36 {
37 for(ll j=n;j>0;--j) //注意这个for循环j得终止条件是j<=0
38 {
39 ll ans;
40 //这个就是背包溢出的处理
41 if(j<m[i].t) ans=0;
42 else ans=j-m[i].t;
43 dp[j]=min(dp[j],dp[ans]+m[i].c);
44 }
45 }
46 printf("%I64d\n",dp[n]);
47 return 0;
48 }

Checkout Assistant CodeForces - 19B的更多相关文章

  1. CodeForces 19B Checkout Assistant

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

  2. B. Checkout Assistant 01背包变形

    http://codeforces.com/problemset/problem/19/B 对于每个物品,能偷多ti个,那么先让ti + 1, 表示选了这个东西后,其实就是选了ti + 1个了.那么只 ...

  3. [CF19B]Checkout Assistant

    题目描述 Bob 来到一家现购自运商店,将 n 件商品放入了他的手推车,然后到收银台 付款.每件商品由它的价格 pi 和收银员扫描它的时间 ti 秒定义.当收银员正在扫 描某件商品时,Bob 可以从他 ...

  4. Codeforces Beta Round #19

    A. World Football Cup #include <bits/stdc++.h> using namespace std;   ; char name[N][N]; map&l ...

  5. CF dp 题(1500-2000难度)

    前言 从后往前刷 update 新增 \(\text{\color{red}{Mark}}\) 标记功能,有一定难度的题标记为 \(\text{\color{red}{红}}\) 色. 题单 (刷过的 ...

  6. codeforces 377A. Puzzles 水题

    A. Puzzles Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/33 ...

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

  8. 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 ...

  9. CodeForces 337A Puzzles

    Puzzles Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origina ...

随机推荐

  1. 【Linux】云服务器部署宝塔linux控制面板环境

    服务器购买及宝塔部署环境说明 简单记录 - 狂神的 服务器购买及宝塔部署环境说明 服务器如何购买 我们尽量趁打折的时候购买,比较便宜点!多看看有活动. 如果是学生,可以购买学生机, 学生机地址:htt ...

  2. 【Software Test】Basic Of ST

    文章目录 Learning Objective Introduction Software Applications Before Software Testing What is testing? ...

  3. 【Linux】centos7中 root家目录中perl5文件夹无法删除问题解决

    由于新项目上线,安装了一些perl的一些包 但是发现,在/root下有一个perl5/的文件夹,删除后,重新登录又会出现,很是烦人,而且他还没有内容,就是一个空文件 那么着手搞掉他 环境:centos ...

  4. oracle新增ID主键列,如何补全旧数据的ID值

    1.创建SEQUENCE CREATE SEQUENCE MONKEY.TEST_ADD_IDCOL_ID CACHE 100; 2.新增表栏位 ALTER TABLE MONKEY.TEST_ADD ...

  5. DOCKER 安装步骤-最靠谱的笔记

    一.系统环境规划 服务器名 项目名称 docker 操作系统 CentOS Linux release 7.1.1503 (Core) Docker 版本 17.03.2-ce   二.Docker ...

  6. Eclipse在线安装FatJar插件失败解决方案

    在线安装fatjar(URL:http://kurucz-grafika.de/fatjar) 快要安装完的时候报错如下: 找了很久解决方法,终于有了下文:很是粗乎意料呃,下载一个eclipse2.0 ...

  7. 研发流程 接口定义&开发&前后端联调 线上日志观察 模型变动

    阿里等大厂的研发流程,进去前先了解一下_我们一起进大厂 - SegmentFault 思否 https://segmentfault.com/a/1190000021831640 接口定义 测试用例评 ...

  8. ACID 原子性(atomicity,或称不可分割性)、一致性(consistency)、隔离性(isolation,又称独立性)、持久性(durability)。

    https://en.wikipedia.org/wiki/ACID https://zh.wikipedia.org/wiki/ACID //ACID compliant , row-level l ...

  9. 跨度实际上是用来计算排位(rank) 目标节点在跳跃表中的排位 有序集 排序计算

    跳跃表的实现 - Redis 设计与实现 http://redisbook.com/preview/skiplist/datastruct.html 有序集合 /* ZSETs use a speci ...

  10. Obligations for calling close() on the iterable returned by a WSGI application

    Graham Dumpleton: Obligations for calling close() on the iterable returned by a WSGI application. ht ...