• HDOJ1085Holding BinLaden Captive!(母函数做法)


    Holding Bin-Laden Captive!

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


    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
     1 /*
     2 构造母函数如下:
     3 G(x)=(1+x+x^2+x^3+...+x^(n1))*(1+x^2+x^4+...+x^(2 * (n2)))*(1+x^5+x^10+...+x^(5*(n5)));
     4 */ 
     5 #include <cstdio>
     6 #include <iostream>
     7 
     8 using namespace std;
     9 
    10 int main()
    11 {
    12     int num[4];
    13     int val[4] = {0, 1, 2, 5};
    14     int c1[8050], c2[8050];
    15     while(scanf("%d%d%d", &num[1], &num[2], &num[3]), num[1] || num[2] || num[3])
    16     {
    17         int tot = num[1] + 2*num[2] + 5*num[3];
    18         
    19         for(int i = 0; i <= num[1]; ++i)
    20         {
    21             c1[i] = 1;
    22             c2[i] = 0;
    23         }
    24         for(int i = num[1]+1; i <= tot+1; ++i)  //  这里一定要到 tot+1 因为最后可能结果会到tot+1,就因为这一点WA了半天了,真坑爹!!
    25             c1[i] = c2[i] = 0;
    26         
    27         for(int i = 2; i <= 3; ++i)
    28         {
    29             for(int j = 0; j <= tot; ++j)
    30             {
    31                 for(int k = 0; k <= num[i]*val[i] && k+j <= tot; k += val[i])
    32                     c2[k+j] += c1[j];
    33             }
    34             for(int j = 0; j <= tot; ++j)
    35             {
    36                 c1[j] = c2[j];
    37                 c2[j] = 0;
    38             }
    39         }
    40         for(int i = 1; i <= tot+1; ++i)
    41         {
    42             if(c1[i] == 0)
    43             {
    44                 printf("%d\n", i);
    45                 break;
    46             }
    47         }
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    洛谷P4172 [WC2006]水管局长(lct求动态最小生成树)
    洛谷P1501 [国家集训队]Tree II(打标记lct)
    洛谷P2173 [ZJOI2012]网络(10棵lct与瞎jb暴力)
    [Asp.net 5] Localization-resx资源文件的管理
    [Asp.net 5] Localization-简单易用的本地化-全球化信息
    [Asp.net 5] Configuration-新一代的配置文件
    [Asp.net 5] Configuration-新一代的配置文件(ConfigurationSource的多种实现)
    [Asp.net 5] Configuration-新一代的配置文件(神奇的Binder)
    [Asp.net 5] Configuration-新一代的配置文件(接口定义与基础实现)
    [Asp.net 5] DependencyInjection项目代码分析-目录
  • 原文地址:https://www.cnblogs.com/dongsheng/p/3046827.html
Copyright © 2020-2023  润新知