zoukankan      html  css  js  c++  java
  • 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): 17732    Accepted Submission(s): 7940


    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
    题解:money数组存的是面值,t数组存的是当前面值的个数
    母函数为:
    (1+x+x^2+x^3+.....+x^a)*(1+x^2+x^4+....+x^2b)*(1+x^5+x^10+...+x^5c);
    代码:
     1 #include<stdio.h>
     2 #include<string.h>
     3 const int MAXN=100010;
     4 int a[MAXN],b[MAXN];
     5 int main(){
     6     int x,y,z,sum;
     7     int money[3],t[3];
     8     while(scanf("%d%d%d",&x,&y,&z),x||y||z){
     9         memset(a,0,sizeof(a));memset(b,0,sizeof(b));//初始化。。。 
    10         for(int i=0;i<=x;i++)a[i]=1,b[i]=0;
    11         t[0]=x;t[1]=y;t[2]=z;
    12         money[0]=1;money[1]=2;money[2]=5;
    13         sum=money[0]*t[0];
    14         for(int i=1;i<3;i++){
    15         for(int j=0;j<=sum;j++)
    16             for(int k=0;k<=money[i]*t[i];k+=money[i])
    17                 b[j+k]+=a[j];
    18                 sum+=money[i]*t[i];
    19             for(int j=0;j<=sum;j++)
    20                 a[j]=b[j];
    21         }
    22         //printf("%d
    ",sum);
    23         for(int i=0;i<=sum+1;i++)
    24             if(!a[i]){
    25                 printf("%d
    ",i);
    26                 break;
    27             }
    28     }
    29     return 0;
    30 } 
    extern "C++"{
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    using namespace std;
    const int INF = 0x3f3f3f3f;
    #define mem(x,y) memset(x,y,sizeof(x))
    typedef long long LL;
    typedef unsigned long long ULL;
    
    void SI(int &x){scanf("%d",&x);}
    void SI(double &x){scanf("%lf",&x);}
    void SI(LL &x){scanf("%lld",&x);}
    void SI(char *x){scanf("%s",x);}
    
    }
    const int MAXN = 100010;
    int a[MAXN],b[MAXN];
    int num[3];
    int v[3];
    int main(){
        while(~scanf("%d%d%d",&num[0],&num[1],&num[2]),num[0]|num[1]|num[2]){
            mem(a,0);mem(b,0);
            v[0] = 1;v[1] = 2;v[2] = 5;
            int sum = 0;
            for(int i = 0;i <= num[0];i++)a[i] = v[0],b[i] = 0,sum += v[i] * num[i];
            //int sum = num[0] * v[0];
            for(int i = 1;i <= 2;i++){
                for(int j = 0;j <= sum;j++){
                    for(int k = 0;k <= num[i];k++){
                        b[j + k * v[i] ] += a[j];
                    }
                }
            //    sum += num[i] * v[i];
                for(int j = 0; j <= sum; j++)a[j] = b[j],b[j] = 0;
            }
            int ans;
            for(int i = 1;i <= sum + 1 ;i++){
                if(a[i] == 0){
                    ans = i;
                    break;
                }
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    XAMPP安装过程中,出现的问题
    Javascript的数据类型和转换
    Vue组件之间的通信
    vue2.0在页面中自定义组件模块,以及页面与组件之间的数据传递
    本地起一个https服务器
    开发人员初始化操作
    添加环境变量
    公钥~gitlab~免密登录
    class继承随笔
    阿里云ECS随笔
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4823630.html
Copyright © 2011-2022 走看看