Hdu 1085 Holding Bin-Laden Captive! (Primary function)
Meaning: 1 RMB, 2 RMB, and 5 RMB coins include num [1], num [2], and num [3. Ask the minimum amount of money that cannot be combined with these coins.
Continue the master function.
There are two notes:
You must also initialize c1 [] During c2 [] initialization.
Finally, sum + 1 is enumerated, because [1, sum] may all be possible. In this case, sum + 1 is output.
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include # define LL long # define _ LL _ int64 # define eps 1e-12 # define PI acos (-1.0) using namespace std; int c1 [8010], c2 [8010]; int add [4] = {,}; int num [4]; int main () {while (~ Scanf (% d, & num [1], & num [2], & num [3]) {if (num [1] = 0 & num [2] = 0 & num [3] = 0) break; int sum = num [1] + num [2] * 2 + num [3] * 5; // maximum amount of money that can be reached memset (c2, 0, sizeof (c2); memset (c1, 0, sizeof (c1); for (int I = 0; I <= num [1]; I ++) {c1 [I] = 1 ;}for (int I = 2; I <= 3; I ++) {for (int j = 0; j <= sum; j ++) {for (int k = 0; k + j <= sum & k <= add [I] * num [I]; k + = add [I]) {c2 [k + j] + = c1 [j] ;}} for (int j = 0; j <= sum; j ++) {c1 [j] = c2 [j]; c2 [j] = 0 ;}}for (int I = 1; I <= sum + 1; I ++) // note that sum + 1 is enumerated, because if [1, sum] can be merged, sum + 1 should be output. {if (c1 [I] = 0) {printf (% d, I); break ;}} return 0 ;}