Coins
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 11596 Accepted Submission (s): 4634
Problem descriptionwhuacmers use coins. They has coins of value a1,a2,a3 ... An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch at a nearby shop. He wanted to pay the exact price (without change) and he known the price would not more than m.but he didn ' t know the exact Price of the watch.
You is to write a program which reads N,M,A1,A2,A3 ... An AND c1,c2,c3 ... Cn corresponding to the number of Tony ' s coins of value a1,a2,a3 ... An and calculate how many prices (Form 1 to m) Tony can pay use these coins.
Inputthe input contains several test cases. The first line of all test case contains, integers n (1≤n≤100), M (m≤100000). The second line contains 2n integers, denoting a1,a2,a3 ... An,c1,c2,c3 ... Cn (1≤ai≤100000,1≤ci≤1000). The last test was followed by the zeros.
Outputfor each test case output of the answer on a single line.
Sample INPUT3 101 2 4 2 1 12 51 4 2 10 0
Sample Output84 Source multi-university Training Contest 3-host by WHU test instructions: There are different denominations of the corresponding number of different n kinds of coins ask the price of 1~m yuan which can be made of coins F[i]==i: Multi-backpack binary optimization
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <map>5#include <queue>6#include <stack>7 using namespacestd;8 intn,m;9 structnodeTen { One inta,c; A} n[ the]; - intf[110005]; - intans; the intvalue[100005],size[100005]; - intcount; - voidSlove (intq) - { +Count=1; - for(intI=1; i<=q;i++) + { A intc=n[i].c,v=n[i].a; at for(intk=1; k<=c; k<<=1) - { -Value[count] = k*v; -size[count++] = k*v; -C-=K; - } in if(C >0) - { toValue[count] = c*v; +size[count++] = c*v; - } the } * } $ intMain ()Panax Notoginseng { - while(SCANF ("%d%d", &n,&m)! =EOF) the { + if(n==0&&m==0) A Break; the for(intI=0; I <= m; i++) +F[i] =0; -ans=0; $ for(intI=1; i<=n;i++) $scanf"%d",&n[i].a); - for(intI=1; i<=n;i++) -scanf"%d",&n[i].c); the slove (n); - for(intI=1; i<count;i++)Wuyi for(intgg=m;gg>=size[i];gg--) theF[gg]=max (f[gg],f[gg-size[i]]+value[i]); - for(intI=1; i<=m;i++) Wu if(f[i]==i) -ans++; Aboutcout<<ans<<Endl; $ } - return 0; -}
HDU 28,442 binary optimized multi-pack