There are five types of coins with a nominal value of 1, 5, 10, 25, and 50 respectively. Now, we provide the amount and ask how many methods can be used to make up the nominal value. Solution: every coin has an infinite number, so it is a typical full backpack. When I first wrote the paper, I did not consider the duplicate face value. When I typed the table, I calculated the amount one by one, however, cnt [I] + = cnt [I-sex [j] is used, and some composition methods are considered again (this is applicable only for those with less than 50, it will not cause repeated considerations of the nominal value, such as 100. When sex [j] = 25, cnt [100] + = cnt [75], however, the composition method in 75 can be composed of 50 values with a nominal value. Therefore, when sex [j] = 50 is calculated, the calculation is repeated) the correct method is cnt [I] + = low (cnt [I-sex [j]) indicates the composition type of cnt [I-sex [j] with a nominal value less than or equal to sex [j. Written in the code.
# Include <stdio. h> # include <string. h> const int N = 7500; const int sex [] = {1, 5, 10, 25, 50}; int n, cnt [N], t; void Init () {memset (cnt, 0, sizeof (cnt); cnt [0] = 1; for (int I = 0; I <5; I ++) {for (int j = sex [I]; j <N; j ++) cnt [j] + = cnt [j-sex [I] ;}} int main () {Init (); while (scanf ("% d", & n) = 1) {printf ("% d \ n ", cnt [n]);} return 0 ;}