zoukankan      html  css  js  c++  java
  • HDU-1085-Holding Bin-Laden Captive!(母函数)

    链接:

    http://acm.hdu.edu.cn/showproblem.php?pid=1085

    题意:

    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!

    思路:

    母函数模板,处理个数。

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<math.h>
    #include<vector>
    
    using namespace std;
    typedef long long LL;
    const int INF = 1e9;
    
    const int MAXN = 1e4+10;
    int co[10] = {0, 1, 2, 5};
    int num[10];
    int c1[MAXN], c2[MAXN];
    int n;
    
    void Init()
    {
        memset(c1, 0, sizeof(c1));
        c1[0] = 1;
        int Max = num[1]+num[2]*2+num[3]*5;
        for (int i = 1;i <= 3;i++)
        {
            for (int j = 0;j <= num[i];j++)
            {
                int val = j*co[i];
                for (int k = 0;k+val <= Max;k++)
                    c2[k+val] = c1[k];
            }
            for (int j = 0;j < MAXN;j++)
            {
                c1[j] = c2[j];
                c2[j] = 0;
            }
        }
    }
    
    int main()
    {
        while(~scanf("%d%d%d", &num[1], &num[2], &num[3]) && (num[1] || num[2] || num[3]))
        {
            Init();
            for (int i = 1;i <= 1*num[1]+2*num[2]+5*num[3]+1;i++)
            {
                if (c1[i] == 0)
                {
                    cout << i << endl;
                    break;
                }
            }
        }
    
        return 0;
    }
    
  • 相关阅读:
    Python之旅.第九章.并发编程.
    Python之旅.第九章.并发编程。
    Python之旅.第九章.并发编程..
    Python之旅.第九章.并发编程
    Python之旅.第九章.并发编程
    animate.css
    JS对于Android和IOS平台的点击响应的适配
    腾讯设计导航
    炫酷照片墙----------------网站也不错的样子
    判断设备是电脑还是手机
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11802820.html
Copyright © 2011-2022 走看看