PKU 1276 Cash Machine
<span style="color:#000099;">/*
Cash Machine
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 26604 Accepted: 9397 Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The machine uses exactly N distinct bill denominations, say Dk, k=1,N, and for each denomination Dk the machine has a supply of nk bills. For example, 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 The program input is from standard input. Each data set in the 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 For each set of data the program prints the result to the 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 The first data set designates a transaction where the amount of cash requested is @735. The machine contains 3 bill denominations: 4 bills of @125, 6 bills of @5, and 3 bills of @350. The machine can deliver the exact amount of requested cash. 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 Southeastern Europe 2002
pku 1276
By ivi
2014.7.1
多重背包
这道题从一開始的转化为01背包的超时,到后来的数组开小的执行时错误,再到超内存、、超时、、,
到最后深夜1:40的AC,过程真辛苦
*/
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int f[13];
int p[13];
bool dp[111113];
int num=0;
int n=0; int main()
{int temp,i;
while(scanf("%d%d",&num,&n)!=EOF){ for(i=1;i<=n;i++)
scanf("%d%d",&f[i],&p[i]);
if(num==0)
cout<<"0"<<endl;
else if(n==0)
cout<<"0"<<endl;
else {
memset(dp,0,num+3);
m=0;
dp[0]=1;
for(int k=1;k<=n;k++) for(int j=m;j>=0;j--)
if(dp[j]){
for(int i=1;i<=f[k];i++)
{
temp=i*p[k]+j;
if(temp<=num)
{
dp[temp]=1;
if(temp>m)
m=temp;
}
}
}
cout<<m<<endl;} }
return 0;
}
</span>
版权声明:本文博主原创文章。博客,未经同意不得转载。
PKU 1276 Cash Machine的更多相关文章
- 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 ...
- POJ 1276 Cash Machine(单调队列优化多重背包)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 38986 Accepted: 14186 De ...
- POJ 1276 Cash Machine -- 动态规划(背包问题)
题目地址:http://poj.org/problem?id=1276 Description A Bank plans to install a machine for cash withdrawa ...
- 【转载】poj 1276 Cash Machine 【凑钱数的问题】【枚举思路 或者 多重背包解决】
转载地址:http://m.blog.csdn.net/blog/u010489766/9229011 题目链接:http://poj.org/problem?id=1276 题意:机器里面共有n种面 ...
- [poj 1276] Cash Machine 多重背包及优化
Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver ap ...
- POJ 1276 Cash Machine(多重背包的二进制优化)
题目网址:http://poj.org/problem?id=1276 思路: 很明显是多重背包,把总金额看作是背包的容量. 刚开始是想把单个金额当做一个物品,用三层循环来 转换成01背包来做.T了… ...
- POJ 1276 Cash Machine(完全背包模板题)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44409 Accepted: 16184 Description A B ...
随机推荐
- fastjson初始化对性能的影响(转)
之前在项目中序列化是用thrift,性能一般,而且需要用编译器生成新的类,在序列化和反序列化的时候感觉很繁琐,因此想转到json阵营.对比了jackson,gson等框架之后,决定用fastjson, ...
- MVC常用特性
MVC常用特性使用 简介 在以前的文章中,我和大家讨论如何用SingalR和数据库通知来完成一个消息监控应用. 在上一篇文章中,我介绍了如何在MVC中对MongoDB进行CRUD操作. 今天,我将 ...
- OpenCV2学习笔记(十四):基于OpenCV卡通图片处理
得知OpenCV有一段时间.除了研究的各种算法的内容.除了从备用,据导游书籍和资料,尝试结合链接的图像处理算法和日常生活,第一桌面上(随着摄像头)完成了一系列的视频流处理功能.开发平台Qt5.3.2+ ...
- 【Java】【Flume】Flume-NG源代码分析的启动过程(两)
本节分析配置文件的解析,即PollingPropertiesFileConfigurationProvider.FileWatcherRunnable.run中的eventBus.post(getCo ...
- Vijos.1096 津津储蓄计划
见问题: https://vijos.org/p/1096 主题概述 津津的零花钱一直都是自己的管理.每月初的母亲津津300美元,津津将于本月支出预算.而且总是做同样的实际支出与预算. 为了让津津学 ...
- 读改善c#代码157个建议:建议7~9
目录: 建议7:将0值作为枚举的默认值 建议8:避免给枚举类型的元素提供显示的值 建议9:习惯运算符重载 一.建议7:将0值作为枚举的默认值 允许使用的枚举类型有:byte.sbyte.short.u ...
- 一键安装 gitlab7 on rhel6.4 并设置邮件发送
一键安装 gitlab7 on rhel6.4 并设置邮件发送 世间本无事,庸人自扰之.书归正传,简短节说:gitlab是个好东西,可是安装手冊奇烂.尽管以前对比文档一步一步安装起来gitlab 6. ...
- 从头到尾彻底理解KMP(转)
引言 KMP原文最初写于2年多前的2011年12月,因当时初次接触KMP,思路混乱导致写也写得非常混乱,如此,留言也是骂声一片.所以一直想找机会重新写下KMP,但苦于一直以来对KMP的理解始终不够,故 ...
- UVA 11987 - Almost Union-Find(并查集)
UVA 11987 - Almost Union-Find 题目链接 题意:给定一些集合,操作1是合并集合,操作2是把集合中一个元素移动到还有一个集合,操作3输出集合的个数和总和 思路:并查集,关键在 ...
- android开源系列:CircleImageView采用圆形控制它们的定义
1.定义自己的圆形控制github住址:https://github.com/hdodenhof/CircleImageView 基本的类: package de.hdodenhof.circleim ...