【HDOJ 1085】数学问题,母函数

Holding Bin-Laden Captive!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17327    Accepted Submission(s): 7764

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 3

0 0 0

Sample Output

4

Author

lcy

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int a,b,c;
    while( cin >> a >> b >> c,a,b,c)
    {
        if(a >= 4 || (a >= 2 && b >=1) || (a >= 1 && b >= 2))
        {
            cout << a + b * 2 + c * 5 + 1 << endl;
            continue;
        }
        if(a == 0)
            cout << "1" << endl;
        else if(b == 0)
            cout << a + 1 << endl;
        else if(a == 1 && b == 1)
            cout << "4" << endl;
    }
    return 0;
}
#include <iostream>
#include <memory.h>
#define N 8000
using namespace std;
int num[4];
int c1[N+10],c2[N+10];
int main()
{
    int i,j,k;
    int value[4]= {0,1,2,5};
    while(cin>>num[1]>>num[2]>>num[3])
    {
        if(num[1]==0&&num[2]==0&&num[3]==0)
            return 0;
        int n=0;
        for(i=1;i<=3;i++)
            n+=num[i]*value[i];
        memset(c1,0,sizeof(c1));
        memset(c2,0,sizeof(c2));
        c1[0]=1;
        for (i=1; i<=3; i++)
        {
            for (j=0; j<=n; j++)
                for (k=0; k*value[i]+j<=n&&k<=num[i]; k++)
                {
                    c2[j+k*value[i]]+=c1[j];
                }
            for (j=0; j<=n; j++)
            {
                c1[j]=c2[j];
                c2[j]=0;
            }
        }
        int s;
        for(s=1;s<=n;s++)
        {
            if(c1[s]==0)
                break;
        }
        cout<<s<<endl;
    }
    return 0;
}
时间: 2024-11-02 23:51:07

【HDOJ 1085】数学问题,母函数的相关文章

hdoj 1085 确定比赛名次 【拓扑排序】

中文题,不解释. 这是我的第一道拓扑排序题,先来讲一下什么是拓扑排序: 拓扑排序其实就是如果要进行某一项活动的时候,它的基础活动要先进行.比如说,学概率论之前必须要学会高等数学,那么高等数学就是学概率论的前提条件,这就牵涉到先后课程怎么学习,就是谁先学谁后学习, 拓扑排序就是解决这类问题的. 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1285 代码: #include<stdio.h> #include<string.h> boo

Holding Bin-Laden Captive!(杭电1085)(母函数)

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15501    Accepted Submission(s): 6951 Problem Description We all know that Bin-Laden is a notorious terrorist, and he

HDOJ Fruit 2152【母函数】

Fruit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3899    Accepted Submission(s): 2217 Problem Description 转眼到了收获的季节,由于有TT的专业指导,Lele获得了大丰收.特别是水果,Lele一共种了N种水果,有苹果,梨子,香蕉,西瓜--不但味道好吃,样子更是好看. 于是

今天开始认真刷数学

不得不说数学是制胜的法宝,但是也确实很难,系统地针对地进行训练十分有必要: VJUDGE自行训练,发布者lvbu: ID   Title   Begin Time Length Owner 165317    [kuangbin]数学训练一 [Cloned]   5 min later 60 days lvbu 165319    [kuangbin]数学训练三 [Cloned]   5 min later 50.2 days lvbu 165318    [kuangbin]数学训练二 cou

母函数及其应用+模板

部分摘自这位大佬的博客https://www.cnblogs.com/linyujun/p/5207730.html 生成函数即母函数,是组合数学中尤其是计数方面的一个重要理论和工具. 最早提出母函数的人是法国数学家LaplaceP.S.在其1812年出版的<概率的分析理论>中明确提出“生成函数的计算”. 生成函数的应用简单来说在于研究未知(通项)数列规律,用这种方法在给出递推式的情况下求出数列的通项. 在这里我们不去高深地研究数学上母函数,而是讲讲简单的母函数应用. 1.母函数引入 就是把一

HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)

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 hi

HDOJ Holding Bin-Laden Captive! 1085【母函数】

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17379    Accepted Submission(s): 7795 Problem Description We all know that Bin-Laden is a notorious terrorist, and he

hdu 1085 Holding Bin-Laden Captive!(母函数)

http://acm.hdu.edu.cn/showproblem.php?pid=1085 题意:1元,2元,5元的硬币分别有num[1],num[2],num[3]个.问用这些硬币不能组合成的最小钱数. 继续母函数. 有两个注意的地方: 对c2[]初始化的同时也要对c1[]初始化. 最后枚举到sum+1,因为存在[1,sum]都可以凑成的可能,这时输出sum+1. #include <stdio.h> #include <iostream> #include <map&g

数学 2015百度之星初赛2 HDOJ 5255 魔法因子

题目传送门 1 /* 2 数学:不会写,学习一下这种解题方式:) 3 思路:设符合条件的数的最高位是h,最低位是l,中间不变的部分为mid,由题意可得到下面的公式(这里对X乘上1e6用a表示,b表示1e6) 4 (h*power+l+mid)*a = (l*power+h+mid)*b 5 可推得:mid = ((h*power+l) * a - (l*power+h) * b) / (a - b); 6 所以可以枚举h,l然后求mid,注意mid的最低位一定是0,因为留出最低位加l或者h 7