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;
    }
    
  • 相关阅读:
    JavaScript的语法、数据类型、基本算数和逻辑运算操作
    ES6之常用开发知识点:入门(一)
    ES6中map数据结构
    VUE路径问题

    JS简易计算器的实现,以及代码的优化
    格雷编码
    H5网页布局+css代码美化
    jQuery---五角星评分案例
    Ajax工作原理及优缺点
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11802820.html
Copyright © 2011-2022 走看看