HDU 1085 Holding Bin-Laden Captive!

来源:互联网 发布:e8票据打印软件注册码 编辑:程序博客网 时间:2024/05/14 03:03
Problem Description
We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China!
“Oh, God! How terrible! ”



Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up!
Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
“Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
You, super ACMer, should solve the problem easily, and don’t forget to take $25000000 from Bush!
 

Input
Input contains multiple test cases. Each test case contains 3 positive integers num_1, num_2 and num_5 (0<=num_i<=1000). A test case containing 0 0 0 terminates the input and this test case is not to be processed.
 

Output
Output the minimum positive value that one cannot pay with given coins, one line for one case.
 

Sample Input
1 1 30 0 0
 

Sample Output
4

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

在数学中,某个序列的母函数(Generating function,又称生成函数)是一种形式幂级数,其每一项的系数可以提供关于这个序列的信息。使用母函数解决问题的方法称为母函数方法

母函数可分为很多种,包括普通母函数指数母函数L级数贝尔级数狄利克雷级数。对每个序列都可以写出以上每个类型的一个母函数。构造母函数的目的一般是为了解决某个特定的问题,因此选用何种母函数视乎序列本身的特性和问题的类型。

 

这里先给出两句话,不懂的可以等看完这篇文章再回过头来看:

1.“把组合问题的加法法则和幂级数的乘幂对应起来”

2.“母函数的思想很简单 — 就是把离散数列和幂级数一 一对应起来,把离散数列间的相互结合关系对应成为幂级数间的运算关系,最后由幂级数形式来确定离散数列的构造. “

 

我们首先来看下这个多项式乘法:

引用了一下网上资料

#include <iostream>using namespace std;#define SIZE 10005int num[4];int c1[SIZE], c2[SIZE];int main(void){    while(cin>>num[1]>>num[2]>>num[3] && !(num[1]==0 && num[2] == 0 && num[3]==0))    {        int _max = num[1]*1 + num[2]*2 + num[3]*5;        for(int i = 0; i <= _max; i++)        {            c1[i] = 0;            c2[i] = 0;        }        for(int i = 0; i <= num[1]; i++)        {            c1[i] = 1;        }        for(int i = 0; i <= num[1]; i++)            for(int j = 0; j <= num[2]*2; j += 2)                c2[j+i] += c1[i];        for(int i = 0; i <= num[1]*1 + num[2]*2; i++) // 看到范围的变化了吗?        {            c1[i] = c2[i];            c2[i] = 0;        }        for(int i = 0; i <= num[1]*1 + num[2]*2; i++)            for(int j = 0; j <= num[3]*5; j += 5)                c2[j+i] += c1[i];        for(int i = 0; i <= num[1]*1 + num[2]*2 + num[3]*5; i++)        {            c1[i] = c2[i];            c2[i] = 0;        }        int i;        for(i = 0; i <= _max; i++)        {            if(c1[i] == 0)            {                cout<<i<<endl;                break;            }        }        if(i == _max+1)            cout<<i<<endl;    }    return 0;}


0 0
原创粉丝点击