POJ1276 Cash Machine
| Time Limit: 1000MS | Memory Limit: 10000KB | 64bit IO Format: %lld & %llu |
Description
N=3, n1=10, D1=100, n2=4, D2=50, n3=5, D3=10
means the machine has a supply of 10 bills of @100 each, 4 bills of @50 each, and 5 bills of @10 each.
Call cash the requested amount of cash the machine should
deliver and write a program that computes the maximum amount of cash
less than or equal to cash that can be effectively delivered according
to the available bill supply of the machine.
Notes:
@ is the symbol of the currency delivered by the machine. For instance, @ may stand for dollar, euro, pound etc.
Input
input stands for a particular transaction and has the format:
cash N n1 D1 n2 D2 ... nN DN
where 0 <= cash <= 100000 is the amount of cash
requested, 0 <=N <= 10 is the number of bill denominations and 0
<= nk <= 1000 is the number of available bills for the Dk
denomination, 1 <= Dk <= 1000, k=1,N. White spaces can occur
freely between the numbers in the input. The input data are correct.
Output
standard output on a separate line as shown in the examples below.
Sample Input
735 3 4 125 6 5 3 350
633 4 500 30 6 100 1 5 0 1
735 0
0 3 10 100 10 50 10 10
Sample Output
735
630
0
0
Hint
In the second case the bill supply of the machine does not
fit the exact amount of cash requested. The maximum cash that can be
delivered is @630. Notice that there can be several possibilities to
combine the bills in the machine for matching the delivered cash.
In the third case the machine is empty and no cash is
delivered. In the fourth case the amount of cash requested is @0 and,
therefore, the machine delivers no cash.
Source
多重背包 单调队列优化
/*By SilverN*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int lim,n;
int m[mxn],v[mxn];
bool f[];
int q[];
int main(){
int i,j;
while(scanf("%d%d",&lim,&n)!=EOF){
memset(f,,sizeof f);
for(i=;i<=n;++i){m[i]=read();v[i]=read();}
f[]=;
for(i=;i<=n;++i){
if(m[i]==){
for(j=lim;j>=v[i];j--)
f[j]=f[j]||f[j-v[i]];
}
else{
for(int k=;k<v[i];++k){
if(k>lim)break;
int hd=,tl=;int smm=;
for(j=k;j<=lim;j+=v[i]){
q[++tl]=f[j];
smm+=f[j];
if(tl-hd>m[i])smm-=q[hd++];
f[j]=f[j]||smm;
}
}
}
}
for(i=lim;i>=;--i)if(f[i]){
printf("%d\n",i);break;
}
}
}
POJ1276 Cash Machine的更多相关文章
- POJ-1276 Cash Machine 多重背包 二进制优化
题目链接:https://cn.vjudge.net/problem/POJ-1276 题意 懒得写了自己去看好了,困了赶紧写完这个回宿舍睡觉,明早还要考试. 思路 多重背包的二进制优化. 思路是将n ...
- POJ1276 - Cash Machine(多重背包)
题目大意 给定一个容量为M的背包以及n种物品,每种物品有一个体积和数量,要求你用这些物品尽量的装满背包 题解 就是多重背包~~~~用二进制优化了一下,就是把每种物品的数量cnt拆成由几个数组成,1,2 ...
- POJ1276:Cash Machine(多重背包)
题目:http://poj.org/problem?id=1276 多重背包模板题,没什么好说的,但是必须利用二进制的思想来求,否则会超时,二进制的思想在之前的博客了有介绍,在这里就不多说了. #in ...
- Poj 1276 Cash Machine 多重背包
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26172 Accepted: 9238 Des ...
- poj 1276 Cash Machine(多重背包)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33444 Accepted: 12106 De ...
- POJ 1276 Cash Machine
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24213 Accepted: 8476 Descrip ...
- PKU 1276 Cash Machine
<span style="color:#000099;">/* Cash Machine Time Limit: 1000MS Memory Limit: 10000K ...
- Cash Machine(多重背包二进制转换)
个人心得:多重背包,自己根据转换方程写总是TLE,后面去网上看了二进制转换,不太理解: 后面仔细想了下,用自己的思想理解下把,就是将对应number,cash总和用二进制拆分, 然后全部装入到一个数组 ...
- POJ 1276 Cash Machine(单调队列优化多重背包)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 38986 Accepted: 14186 De ...
随机推荐
- Web自动化测试框架-PO模式
Web自动化测试框架(WebTestFramework)是基于Selenium框架且采用PageObject设计模式进行二次开发形成的框架. 一.适用范围:传统Web功能自动化测试.H5功能自动化测试 ...
- Java核心技术梳理-异常处理
一.引言 异常总是不可避免的,就算我们自身的代码足够优秀,但却不能保证用户都按照我们想法进行输入,就算用户按照我们的想法进行输入,我们也不能保证操作系统稳定,另外还有网络环境等,不可控因素太多,异常也 ...
- SQL常用系统信息语句
一.查询指定表外键约束 SELECT A.name AS 约束名 , OBJECT_NAME(B.parent_object_id) AS 外键表 , D.name AS ...
- Windows Phone8.1应用 提交
昨天晚上,试了试把一个WP8.1应用提交到微软商店上去,期间遇到了不少问题,搞到凌晨还没弄好.今天早上,终于把WP8.1应用成功提交上去了. 下面说说如何把WP8.1应用提交商店去.提交WP8.1以及 ...
- c#中out参数的作用
给你个简单的解释说法吧.虽然不完全对.但是我可以让你理解OUT有什么作用.呵呵 举个例子.每个方法只能有一个返回值.但是你想有多个返回值,呵呵.OUT就起作用了啊.比如分页,不光返回数据,还要返回总记 ...
- swiper移动端下不能正常轮播的解决方案-----此坑没躺过估计很难找到正确姿势
<script> var mySwiper = new Swiper('.swiper-container', { direction: 'vertical', //horizontal横 ...
- 纯CSS3来自定义单选框radio与复选框checkbox
单选框(radio)自定义样式 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3 ...
- 扩展 IHttpModule
上篇提到请求进入到System.Web后,创建完HttpApplication对象后会执行一堆的管道事件,然后可以通过HttpModule来对其进行扩展,那么这篇文章就来介绍下如何定义我们自己的mod ...
- windows远程桌面链接“发生身份验证错误。要求的函数不受支持”
解决办法: 开始菜单->运行gpedit.msc 打开配置项:计算机配置>管理模板>系统>凭据分配>加密Oracle修正 选择启用并选择易受攻击,配置保存后即可解决问题 ...
- run loop
Objective-C之run loop详解 作者:wangzz 原文地址:http://blog.csdn.net/wzzvictory/article/details/9237973 转载请注明出 ...