Checkout Assistant CodeForces - 19B
题意:
给你n个物品,每个物品有一个价格ci和一个支付时间ti,在这个ti时间内,你可以免费拿ti个物品。问你想要带走这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的更多相关文章
- CodeForces 19B Checkout Assistant
B. Checkout Assistant time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 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 ...
随机推荐
- 安装sendmail
yum install -y sendmail yum install -y sendmail-cf 启动 service sendmail start 发送邮件 cat nihao.txt |mai ...
- 【Oracle】translate函数用法解析
转自:https://blog.csdn.net/shwanglp/article/details/52814173 基本语法: translate(string,from_str,to_str); ...
- bash shell数组使用总结
本文为原创博文,转发请注明原创链接:https://www.cnblogs.com/dingbj/p/10090583.html 数组的概念就不多说了,大家都懂! shell数组分为索引数组和关联数 ...
- 修改conda和pip源
修改conda源为中科大源 Windows修改C:\Users\user(user替换为当前登陆系统的用户)目录下的.condarc文件 Linux修改家目录下的.condarc文件 channels ...
- Poj-P2533题解【动态规划】
本文为原创,转载请注明:http://www.cnblogs.com/kylewilson/ 题目出处: http://poj.org/problem?id=2533 题目描述: 如果ai1 < ...
- uni-app开发经验分享十: 封装request请求
http.js //封装requset,uploadFile和downloadFile请求,新增get和post请求方法 let http = { 'setBaseUrl': (url) => ...
- 转 16 jmeter中的监听器以及测试结果分析
16 jmeter中的监听器以及测试结果分析 常用监听器 断言结果.查看结果树.聚合报告.Summary Report.用表格查看结果.图形结果.aggregate graph等 指标分析 -Sa ...
- 浅谈java中线程和操作系统线程
在聊线程之前,我们先了解一下操作系统线程的发展历程,在最初的时候,操作系统没有进程线程一说,执行程序都是串行方式执行,就像一个队列一样,先执行完排在前面的,再去执行后面的程序,这样的话很多程序的响应就 ...
- 配接Cisco设备
- 超微服务器重置ipmi登录密码
超微服务器的ipmi登录密码不对,需要重置但是bios内并没有找到可以设置的选项. 以下是解决办法: 安装IPMITOOLyum install ipmitool -y 执行以下命令加载模块:modp ...