Question: uva147-dollars (full backpack)
11 coins are given, and a number is given to ask how many methods can be made up of the coins given above. Attention should be paid to the accuracy error. The question may contain 20.005 of such data. Although I think this is illegal data, it will be given and you need to rounded up.
Solution: A full backpack.
Code:
# Include <cstdio> # include <cstring> const int n = 11; const int maxn = 30005; const int C [N] = {5, 10, 20, 50,100,200,500,100 0, 2000,500 0, 10000}; typedef long ll; ll f [maxn]; void Init () {memset (F, 0, sizeof (f )); f [0] = 1; for (INT I = 0; I <n; I ++) for (Int J = C [I]; j <= maxn-5; j ++) f [J] + = f [J-C [I];} int main () {Init (); float num; int N; while (1) {scanf ("% F", & num); n = (Num + 0.005 )* 100; If (! N) break; printf ("% 6.2f % 17lld \ n", num, F [N]);} return 0 ;}
Uva147-dollars (full backpack)