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 ...
随机推荐
- 转 php中$_request与$_post、$_get的区别
php中有$_REQUEST与$_POST.$_GET用于接受表单数据,当时他们有何种区别,什么时候用那种最好. 一.$_REQUEST与$_POST.$_GET的区别和特点 $_REQUEST[]具 ...
- Mybatis事务处理
知识点有事务处理的配置,还有事务处理的方法 事务处理的配置: mybatis的事务处理由两种方式控制,JDBC和MANAGED: MANAGED就是说事务处理由第三方的插件来完成,比如说spring ...
- Android的handler消息机制
Hnadler机制中有这么几部分构成,包括 handler.Message.Looper和MessageQueue.要想在一个线程中使用Handler的话必须要有Looper和MessageQueue ...
- $.extend(x,y); 函数用法介绍。
第一篇资料: 转自: https://www.cnblogs.com/yuqingfamily/p/5813650.html 语法:jQuery.extend( [deep ], target, o ...
- [BZOJ1008][HNOI2008]越狱 组合数学
http://www.lydsy.com/JudgeOnline/problem.php?id=1008 正着直接算有点难,我们考虑反着来,用全集减补集. 总的方案数为$m^n$.第一个人有$m$种可 ...
- contact用法解析
经典用法: mysql> select concat('11','22','33'); +------------------------+ | concat('11','22','33') | ...
- jsdk之微信分享流程
.步骤一:绑定域名 先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”. 备注:登录后可在“开发者中心”查看对应的接口权限. .步骤二:引入JS文件 在需要调用JS接口的页面 ...
- 【Gambit】Gambit使用教程
第一章 Gambit使用 Gambit介绍 网格的划分使用Gambit软件,首先要启动Gambit,在Dos下输入Gambit <filemane>,文件名如果已经存在,要加上参数-old ...
- arcpy利用XY创建点
# -*- coding: utf-8 -*-"""Created on Sun Apr 7 15:32:24 2019@author: ""&quo ...
- vue 写一个聊天工具
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...