poj 1276 Cash Machine
来源:互联网 发布:期货农产品数据库建立 编辑:程序博客网 时间:2024/06/08 14:42
Description
A Bank plans toinstall a machine for cash withdrawal. The machine is able todeliver appropriate @ bills for a requested cash amount. Themachine 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 deliverand write a program that computes the maximum amount of cash lessthan or equal to cash that can be effectively delivered accordingto the available bill supply of the machine.
Notes:
@ is the symbol of the currency delivered by the machine. Forinstance, @ 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 deliverand write a program that computes the maximum amount of cash lessthan or equal to cash that can be effectively delivered accordingto the available bill supply of the machine.
Notes:
@ is the symbol of the currency delivered by the machine. Forinstance, @ may stand for dollar, euro, pound etc.
Input
The program input isfrom standard input. Each data set in the input stands for aparticular transaction and has the format:
cash N n1 D1 n2 D2 ... nN DN
where 0 <= cash <= 100000 is theamount of cash requested, 0 <=N <= 10is the number of bill denominations and 0 <= nk<= 1000 is the number of available bills for the Dkdenomination, 1 <= Dk <= 1000, k=1,N.White spaces can occur freely between the numbers in the input. Theinput data are correct.
cash N n1 D1 n2 D2 ... nN DN
where 0 <= cash <= 100000 is theamount of cash requested, 0 <=N <= 10is the number of bill denominations and 0 <= nk<= 1000 is the number of available bills for the Dkdenomination, 1 <= Dk <= 1000, k=1,N.White spaces can occur freely between the numbers in the input. Theinput data are correct.
Output
For each set of datathe program prints the result to the standard output on a separateline 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
Hint
The first data setdesignates a transaction where the amount of cash requested is@735. The machine contains 3 bill denominations: 4 bills of @125, 6bills of @5, and 3 bills of @350. The machine can deliver the exactamount of requested cash.
In the second case the bill supply of the machine does not fit theexact amount of cash requested. The maximum cash that can bedelivered is @630. Notice that there can be several possibilitiesto combine the bills in the machine for matching the deliveredcash.
In the third case the machine is empty and no cash is delivered. Inthe fourth case the amount of cash requested is @0 and, therefore,the machine delivers no cash.
In the second case the bill supply of the machine does not fit theexact amount of cash requested. The maximum cash that can bedelivered is @630. Notice that there can be several possibilitiesto combine the bills in the machine for matching the deliveredcash.
In the third case the machine is empty and no cash is delivered. Inthe fourth case the amount of cash requested is @0 and, therefore,the machine delivers no cash.
Source
Southeastern Europe 2002
题目大意:给出cash和n,还有n种面值的钞票,各d[i]张,求能取到不大于cash的最大价值。
多重背包。将每种面值的d拆成1,2,4,8,16,32,...,2^k,d[i]-2^(k+1)+1张,进行0-1背包的操作。
ACCODE
programpku_1276;
var f:array[0..100000] of boolean;
d,vv,v:array[1..1000] of longint;
n,nn,c:longint;
//============================================================================
procedure divide;
var i,j:longint;
begin
n:=0;
for i:=1 to nn do
begin j:=0;
while truedo
if 1 shl (j+1)-1<=d[i] then
begin
inc(n);
v[n]:=vv[i]*1 shl j;
inc(j);
end else break;
if d[i]-1shl j+1>0 then
begin
inc(n);
v[n]:=vv[i]*(d[i]-1 shl j+1);
end;
end;
end;
//============================================================================
procedure work;
var i,j:longint;
begin
read(c,nn);
for i:=1 to nn do
read(d[i],vv[i]);
divide;
for i:=1 to c do f[i]:=false;
f[0]:=true;
for i:=1 to n do
for j:=cdownto v[i] do
f[j]:=f[j] or f[j-v[i]];
for i:=c downto 0 do
if f[i]then
begin
writeln(i);
break;
end;
end;
//============================================================================
begin
while not(seekeof) do work;
end.
var f:array[0..100000] of boolean;
//============================================================================
procedure divide;
var i,j:longint;
begin
end;
//============================================================================
procedure work;
var i,j:longint;
begin
end;
//============================================================================
begin
end.
0 0
- poj 1276 Cash Machine
- poj 1276 Cash Machine(多重背包…
- poj 2455 Secret Milking Machine…
- poj 1325 Machine Schedule(匈牙…
- poj 2488
- POJ 2485 Highways
- The Machine Learning Dictionary
- Safe Cash Payment宣布…
- POJ 3299
- poj 1905
- ACM: dp题 poj 1276 go on 动态规…
- Journal of Machine Learning Rese…
- POJ 2247 Humble Numbers
- POJ 1753 Flip Game
- POJ 1182 食物链
- POJ 3185 The Water Bowls
- POj 2379 ACM Rank Table
- POJ 1018 Communication System
- poj 2387 Til the Cows Come Home
- poj 3128 Leonardo's Notebook
- 多米诺覆盖
- Charm Bracelet
- poj 3093 Margaritas on the River…
- poj 1276 Cash Machine
- poj 1742 Coins
- poj 1014 Dividing
- poj 2777 Count Color
- poj 3254Corn Fields
- poj 3126 Prime Path
- poj 1664 放苹果
- poj 3903 Stock Exchange
- 向量旋转