zoukankan      html  css  js  c++  java
  • Holding BinLaden Captive!(母函数写法)

    Holding Bin-Laden Captive!

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


    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
     
    Author
    lcy
     
        本题用母函数写法AC!看过母函数的相关知识之后,我没有理解透百度百科上提供的母函数代码,后来花了不少时间去理解!感觉明白后就开始自己独立写出它,但还是漏洞百出,花费了一些时间来调试!但还好,最终还是找到了问题!
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 int c1[8005], c2[8005];
     5 
     6 int main(int argc, char *argv[])
     7 {
     8 
     9     int i, j, k;
    10     int value[5] = {0,1,2,5,0};
    11     int num[5] = {0};
    12     while( (scanf( "%d%d%d",&num[1],&num[2],&num[3] )!= EOF)&&(num[1]||num[2]||num[3]) )
    13     {
    14            memset(c1,0,sizeof(c1));
    15            memset(c2,0,sizeof(c2));
    16            for( i = 0; i <= num[1]; i++ )
    17                 c1[i] = 1;
    18            for( i = 2; i <= 3; i++ )
    19            {
    20                 for( j = 0; j < 8005; j++ )
    21                      for( k = 0; (k <= num[i] * value[i])&&(k+j<8005); k += value[i] )
    22                           c2[k+j] += c1[j];
    23 
    24                     for( j = 0; j < 8005; j++ )
    25                     {
    26                         c1[j] = c2[j];
    27                         c2[j] = 0;
    28                     }
    29                 }
    30            for( i = 0; i < 8005; i++ )
    31                 if( c1[i] == 0 )
    32                     break;
    33            printf( "%d\n", i );
    34     }     
    35   return 0;
    36 }
    View Code
     
     
  • 相关阅读:
    关于application/x-www-form-urlencoded编码
    socket 状态
    TCP/IP三次握手详解
    一步步优化JVM四:决定Java堆的大小以及内存占用
    编码问题
    git 应用
    父与子继承
    python try except
    python 编码问题
    requests 库使用方法
  • 原文地址:https://www.cnblogs.com/yizhanhaha/p/3086523.html
Copyright © 2011-2022 走看看