Holding Bin-Laden Captive!(母函数)

题目描述

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 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 the minimum positive value that one cannot pay with given
coins, one line for one case.

Sample Input

1 1 3
0 0 0 

Sample Output:

4

具体代码

#include <iostream>
#include<stdio.h>
const int max1=5000+2000+1000+1;
using namespace std;
int a[max1],b[max1];
int main()
{
    int n;
    int num1,num2,num5;
    while( scanf("%d%d%d",&num1,&num2,&num5))
    {
        if(num1==0&&num2==0&&num5==0)
            break;
        int n;
        n=1*num1+2*num2+5*num5;
        for(int i=0; i<=n; i++)
        {
            a[i]=0;
            b[i]=0;
        }//初始化
        for(int i=0;i<=num1;i++)//将num1个1初始为1
            a[i]=1;
        int s=num1;//作为1的(1+x+x^2---x^num1)里的循环数
        int h=num2;//作为1的(1+x^2+x^4---x^(2^num2))里的循环数
        for(int i=2; i<=5; i+=3) //2个开始,5结束,
        {
            for(int j=0; j<=s; j++)//第一次1的()×2的(),结束条件为所有1的和;第二次第一次结果的()×5的(),结束条件为所有1和2的和
                for(int k=0; k<=i*h; k+=i) //第一次结束条件为所有2的和;第二次结束条件为所有5的和
                {
                    b[k+j]+=a[j];//后大括号和前一个大括号相加(乘)
                }
            for(int j=0; j<=s+h*i; j++)
            {
                a[j]=b[j];
                b[j]=0;
            }
            s=num2*2+num1;//作为第二次j的结束条件
            h=num5;//作为第二次k的结束条件
        }
        int shu;
        for(shu=0;shu<=n;shu++)
        {
            if(a[shu]==0)
            {
               printf("%d\n",shu);
               break;
            }

        }
        if(shu==n+1)
            printf("%d\n",shu);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值