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 ...
随机推荐
- 【原创】构建高性能ASP.NET站点 第七章 如何解决内存的问题(前中篇)—托管资源优化—监测CLR性能
原文:[原创]构建高性能ASP.NET站点 第七章 如何解决内存的问题(前中篇)-托管资源优化-监测CLR性能 构建高性能ASP.NET站点 第七章 如何解决内存的问题(前中篇)—托管资源优化—监测C ...
- Android中的表格布局TableLayout
表格布局最基本的三个属性: XML代码实例: <?xml version="1.0" encoding="utf-8"?> <LinearLa ...
- SDUT 2498-AOE网上的关键路径(spfa+字典序路径)
AOE网上的关键路径 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 一个无环的有向图称为无环图(Directed Acycl ...
- 吐槽一下Activiti用户手册和一本书
业余没事的时候,读点Java轮廓,无意中发现Activiti.我们打算跑了几个例子来看看它是如何. 我们一直从事低层次.我们在上面的照顾偶尔有精确地的程度不是什么. 这个过程是如此悲惨开始.第一Act ...
- Team Foundation Server 2015使用教程--tfs用户账号切换
- css3制作一个漂亮的按钮
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFMAAAA4CAIAAAAO41POAAAGWklEQVRogeWabWwTdRzH/8EwMb6Q69
- 百度地图 Android SDK - 个性化地图
什么是百度个性化地图Android SDK? 百度个性化地图Android SDK是一套基于Android 2.2及以上版本号设备的应用程序接口,您能够通过该套接口实现主要的地图功能,而且能够定制地图 ...
- 选择一个利于SEO的空间
大家好.今天蜗牛将给大家分享怎么选择一个利于SEO的站点空间. 一.什么是站点空间? 站点空间,是用来存你的站点的HTML,.图片.文件等的一个远程硬盘空间(就像你的电脑里面的空间一回事儿).依据不同 ...
- 以正确的方式开源 Python 项目(转)
大多数Python开发者至少都写过一个像工具.脚本.库或框架等对其他人也有用的工具.我写这篇文章的目的是让现有Python代码的开源过程尽可能清晰和无痛.我不是简单的指——“创建一个GitHub库,提 ...
- git 如何让单个文件回退到指定的版本
1.进入到文件所在文件目录,或者能找到文件的路径查看文件的修改记录 1 $ git log MainActivity.java 结果: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...