POJ 1276 Cash Machine
来源:互联网 发布:遗传算法 应用 编辑:程序博客网 时间:2024/05/21 09:33
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.
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.
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 350633 4 500 30 6 100 1 5 0 1735 00 3 10 100 10 50 10 10
Sample Output
73563000
题解:
多重背包问题,可用把给的每种东西的数量化为二进制的方法做,比如13化为1,2,4,6。
#include<stdio.h>#include<string.h>int f[100001];int v;int max1(int a,int b){return a>b?a:b;}void zhong(int c,int w,int conut ){if(c*conut>=v){for(int i=c;i<=v;i++)f[i]=max1(f[i],f[i-c]+w);return ;}int k=1;while(k<conut){for(int i=v;i>=k*c;i--) f[i]=max1(f[i],f[i-k*c]+k*w);conut=conut-k;k=k*2;}for(int i=v;i>=conut*c;i--)f[i]=max1(f[i],f[i-conut*c]+conut*w);}int main(){int n,i,c,w;while(scanf("%d",&v)!=EOF){memset(f,0,sizeof(f));scanf("%d",&n);for(i=0;i<n;i++){scanf("%d%d",&c,&w);zhong(w,w,c);}if(n==0||v==0){printf("0\n");continue;}printf("%d\n",f[v]);}return 0;}
- poj 1276 Cash Machine
- poj 1276 Cash Machine
- poj 1276Cash Machine
- POJ 1276 Cash Machine
- poj 1276 Cash machine
- poj 1276 Cash Machine
- poj 1276 Cash Machine
- POJ 1276 Cash Machine
- POJ 1276 Cash Machine
- POJ 1276 Cash Machine
- poj 1276 Cash Machine
- POJ-1276Cash Machine
- POJ 1276 cash machine
- POJ 1276 Cash Machine
- POJ 1276 Cash Machine
- POJ 1276 Cash Machine
- POJ 1276 Cash Machine
- POJ-1276-Cash Machine
- 创造一个智能科学的系统
- Background processing with IntentService class
- 内存越界 莫名其名的crash
- EL表达式格式化日期
- javaScript 中的 with 函数
- POJ 1276 Cash Machine
- 指向指针的指针相关
- C++设计模式
- 软中断与硬中断
- 孙鑫VC++深入详解:Lesson5 Part4 屏幕字符串滚动输出,DrawText,SetTimer,WM_Timer消息
- 主流 编程语言 比较
- node.js 模拟登录新浪微博
- 用RMAN 备份异机恢复 迁移数据
- POJ 2560 Freckles------最小生成树(水啊)