母函数训练C题  HDU 1085

C - Holding Bin-Laden Captive!
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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 3
0 0 0
 
   
4

我们都知道本•拉登为首的是一个臭名昭著的恐怖分子,他已经消失了很长一段时间。但最近,据报道,他隐藏在中国的杭州!

“哦,上帝!多么可怕!”

别那么害怕,伙计们。虽然他隐藏在杭州的某个山洞里,但他不敢出去。拉登是如此无聊,这几年他开始研究一些数学问题,而且他说,如果有人能解决他的问题,他就自杀!

显然,拉登对于他的智商很自信。那么,他的问题是什么呢?
       “给一些中国的硬币,面值分别为1、2、5,并且这些硬币的数量分别为num_1,num_2 和num_5 ,请输出不能用这些硬币表示的最小的值。”
       相信你一定能解决这个问题。


思路:用母函数思想,设输入a,b,c;

则需要求(x^0+x^1+x^2+……+x^a)*(x^2+x^4+x^6+……+x^2*b)(x^5+x^10+……+x^5*c)这三项展开之后每一个幂的系数哪一个




#include <string.h>
#include <iostream>

using namespace std;
int c1[10000],c2[10000];
int main()
{
    int a,b,c,i,j;
    while(cin>>a>>b>>c&&(a||b||c))
    {
        memset(c1,0,sizeof(c1));
        int n=a+2*b+5*c;//n求得最大值
        for(i=0;i<=a;i++)
            {c1[i]=1;}
        for(i=0;i<=a;i++)
            for(j=0;j<=2*b;j+=2)
            c2[i+j]+=c1[i];
            for(i=0;i<=a+2*b;i++)
            {
                c1[i]=c2[i];
                c2[i]=0;
            }
            for(i=0;i<=a+2*b;i++)
            for(j=0;j<=5*c;j+=5)
            c2[i+j]+=c1[i];
        for(i=0;i<=n;i++)
            {
                c1[i]=c2[i];
                c2[i]=0;
            }
    int ans=n+1;//找不到就是最大值加一
    //for(i=0;i<100;i++)cout<<c1[i]<<" ";
    for(i=0;i<=n;i++)
    if(c1[i]==0){ans=i;break;}
      cout<<ans<<endl;
    }

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值