• 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;
    }
    
  • 相关阅读:
    JSON排序
    iOS常用控件尺寸大集合
    Android 平台下Ftp 使用模拟器需要注意的问题
    PhoneGap Html5 App 横竖屏切换自动退出
    加减密 DES
    入学测试题
    黑马程序员——JAVA基础之反射
    黑马程序员——JAVA基础之网络编程
    黑马程序员——JAVA基础之正则表达式,网络爬虫
    黑马程序员——JAVA基础之GUI
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11802820.html
Copyright © 2020-2023  润新知