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 ...
随机推荐
- Windows在生产体系Android开关机动画
在Windows根据系统.办Android开关机动画,几个需要注意的问题: 1.压缩的选择 2.压缩的格式: 版权声明:本文博客原创文章,博客,未经同意,不得转载.
- 提升Mac os x 10.10+xcode6.1之后,Cocoapods发生故障的解决方案
提升Mac OS X 10.10+Xcode 6.1之后.Cocoapods图书馆管理也依赖于相应升级.现在最新的Release版本号是 0.34.在之前的版本号.当数据库更新和管理,你会遇到一个错误 ...
- 看你的门-攻击服务器(4)-HTTP参数注入攻击
首先需要声明.这纯粹是没有远见和有点真才实学开发一个愚蠢的观点,只为web参考系统安全. 1.HTTP参数注入攻击 參数,被用做后端HTTP请求中的參数,这个时候就有可能会导致HTTP參数注入. 一个 ...
- 设置SQLServer数据库中某些表为只读的多种方法
原文:设置SQLServer数据库中某些表为只读的多种方法 翻译自:http://www.mssqltips.com/sqlservertip/2711/different-ways-to-make- ...
- 编写爬虫程序的神器 - Groovy + Jsoup + Sublime(转)
写过很多个爬虫小程序了,之前几次主要用C# + Html Agility Pack来完成工作.由于.NET FCL只提供了"底层"的HttpWebRequest和"中层& ...
- MVC把随机产生的字符串转换为图片
原文:MVC把随机产生的字符串转换为图片 Insus.NET在这篇中<在ASP.NET MVC应用程序中随机获取一个字符串>http://www.cnblogs.com/insus/p/3 ...
- opencv-阈值处理
从原理:http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/imgproc/threshold/threshold.html 目标: ...
- java NIO中的Reactor相关知识汇总 (转)
一.引子 nio是java的IO框架里边十分重要的一部分内容,其最核心的就是提供了非阻塞IO的处理方式,最典型的应用场景就是处理网络连接.很多同学提起nio都能说起一二,但是细究其背后的原理.思想往往 ...
- ORACLE在表中添加的目光凝视和读取列
在ORACLE中给表.列添加凝视以及读取凝视 1.给表填加凝视:SQL>comment on table 表名 is '表凝视"; 2.给列加凝视:SQL>comment on ...
- sk_buff整理笔记(两、操作函数)
承接上一:sk_buff 整理笔记(一.数据结构)这一篇要讲的是内核为sk_buff结构提供的一些操作函数. 第一.首先要讲的是sk_buff中的四大指针: 四大指针各自是:head.data.tai ...