HDU_1085 Holding Bin-Laden Captive!(生成函数)
/*按照母函数的思路,然后模拟三个括号相乘的过程。因为题目已经限定好了硬币只能
是1、2、5。
所以可以写成:
(1 + X + X^2 + ...)(1 + X^2 + X^4 + X^6 + ...)(1 + X^5 + X^10 + X^15 + ...)
其中三个括号元素的个数分别是输入的num_1, num_2, num_3。然后就是模拟多项式相乘了。*/
//ps:代码有点水,一步一步乘的,反正就三个括号,费不了多大劲,^_^
//My Code:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int N = 10000;
int c1[N], c2[N];
int main() {
//freopen("data.in", "r", stdin);
int num_1, num_2, num_3;
int i, j, k, sum;
while(cin >> num_1 >> num_2 >> num_3) {
if(!num_1 && !num_2 && !num_3) break;
memset(c1, 0, sizeof(c1));
memset(c2, 0, sizeof(c2));
//1
for(i = 0; i <= num_1; i++) {
c1[i] = 1; c2[i] = 0;
}
sum = num_1 + 2*num_2;
//2
for(j = 0; j <= num_1; j++) {
for(k = 0; k <= 2*num_2; k += 2) {
c2[k+j] += c1[j];
}
}
for(j = 0; j <= sum; j++) {
c1[j] = c2[j]; c2[j] = 0;
}
//5
for(j = 0; j <= sum; j++) {
for(k = 0; k <= 5*num_3; k += 5) {
c2[k+j] += c1[j];
}
}
for(j = 0; j <= sum + 5*num_3; j++) {
if(c2[j] == 0) break;
}
printf("%d\n", j);
}
return 0;
}