HDU 1085 Holding Bin-Laden Captive! (Primary function)
Question address
Question:
Here is a cnt1 one-dollar coin, cnt2 two-Yuan coin, and cnt3 five-Yuan coin.
Analysis:
Primary function, formula:
(1 + x ^ 2 + x ^ 3 + ...... x ^ cnt1 )? (1 + x ^ 2 + x ^ 4 + x ^ 6 +... x ^ cnt2 )? (1 + x ^ 5 + x ^ 10 + x ^ 15 +... x ^ cnt5)
Directly simulate it.
Code:
/** Author: illuz
* File: 1085. cpp * Create Date: 2014-05-25 11:34:37 * Descripton: Generating Function */# include
# Include
Const int N = 1e4; int val [3] = {1, 2, 5}, cnt [3]; int c1 [N], c2 [N], mmax; int main () {while (~ Scanf ("% d", & cnt [0], & cnt [1], & cnt [2]) & (cnt [0] | cnt [1] | cnt [2]) {memset (c1, 0, sizeof (c1); memset (c2, 0, sizeof (c2); mmax = 0; for (int I = 0; I <3; I ++) mmax + = cnt [I] * val [I]; for (int I = 0; I <= cnt [0]; I ++) // process the first coin c1 [I] = 1; for (int I = 1; I <3; I ++) {// for each coin behind 1 (int j = 0; j <= mmax; j ++) {if (c1 [j]! = 0) {// for the previous item (c1) for (int k = 0; k <= val [I] * cnt [I]; k + = val [I]) {// simulate multiplication with the current formula if (j + k <= mmax) c2 [j + k] + = c1 [j] ;}}// Save the current item in c1 and clear c2memcpy (c1, c2, sizeof (c1 )); memset (c2, 0, sizeof (c2);} int I; for (I = 0; I <= mmax; I ++) {if (c1 [I] = 0) break;} printf ("% d \ n", I);} return 0 ;}