zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    Query实例的ajax应用之二级联动的后台是采用php来做的
    关于jquery的css的一些知识
    这个代码给所有带有name属性的链接加了一个背景色
    jQuery生成一个DIV容器,ID是"rating".
    被included或者被required的文件都来自哪里呢
    msql_createdb: 建立一个新的 mSQL 数据库。
    php中调用这个功能可以在web页面中显示hello world这个经典单词
    啦啦啦测试心得
    maven命令
    robotframework使用
  • 原文地址:https://www.cnblogs.com/dongsheng/p/3046827.html
Copyright © 2011-2022 走看看