zoukankan      html  css  js  c++  java
  • HDOJ 1085 Holding Bin-Laden Captive! (母函数)

    Holding Bin-Laden Captive!

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


    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
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 
     5 using namespace std;
     6 
     7 const int maxn=1010000;
     8 const int valu[4]={0,1,2,5};
     9 int c1[maxn],c2[maxn];
    10 int a,b,c;
    11 
    12 void isOK()
    13 {
    14     int t[4];
    15     t[0]=0;t[1]=a;t[2]=b;t[3]=c;
    16     memset(c1,0,sizeof(c1));
    17     memset(c2,0,sizeof(c2));
    18     int n=1*t[1]+2*t[2]+5*t[3];//最大的项数
    19     for(int i=0;i<=a;i++)
    20     {
    21         c1[i]=1;
    22     }
    23     for(int i=2;i<=3;i++)//层数的限制
    24     {
    25         for(int j=0;j<=n;j++)
    26         {
    27             for(int k=0;k+j<=n&&k<=valu[i]*t[i];k+=valu[i])//个数的限制
    28             {
    29                 c2[k+j]+=c1[j];
    30             }
    31         }
    32         for(int j=0;j<=n;j++)
    33         {
    34             c1[j]=c2[j];  c2[j]=0;
    35         }
    36     }
    37 
    38     for(int i=0;i<=n+1;i++)
    39     {
    40         if(c1[i]==0)
    41         {
    42             printf("%d
    ",i);
    43             break;
    44         }
    45     }
    46 }
    47 
    48 int main()
    49 {
    50 while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    51 {
    52     if(a==0&&b==c&&c==0) break;
    53     isOK();
    54 }
    55     return 0;
    56 }
  • 相关阅读:
    Java描述设计模式(18):享元模式
    Java描述设计模式(17):调停者模式
    微服务架构案例(06):通过业务、应用、技术、存储方面,聊聊架构
    微服务架构案例(05):SpringCloud 基础组件应用设计
    微服务架构案例(04):中间件集成,公共服务封装
    微服务架构案例(03):数据库选型简介,业务数据规划设计
    微服务架构案例(02):业务架构设计,系统分层管理
    Java描述设计模式(16):代理模式
    讲解mybaits的标签语法
    java程序设计原则
  • 原文地址:https://www.cnblogs.com/CKboss/p/3165208.html
Copyright © 2011-2022 走看看