hdu 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): 17256    Accepted Submission(s): 7734

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

Recommend

We have carefully selected several similar problems for you:  1171 2152 2082 1709 2079

#include<stdio.h>
#include<string.h>
int c[10000],temp[10000];
int cost[3]={1,2,5};
int num[3];
int main(){
   while(scanf("%d%d%d",&num[0],&num[1],&num[2])!=EOF){
      if(num[0]==0&&num[1]==0&&num[2]==0)
        break;
        int total=num[0]*1+num[1]*2+num[2]*5;
      memset(c,0,sizeof(c));
      memset(temp,0,sizeof(temp));
      for(int i=0;i<=num[0];i++)
        c[i]=1;

        for(int i=1;i<3;i++){
            for(int j=0;j<=total;j++){
                for(int k=0;k+j<=total&&k/cost[i]<=num[i];k+=cost[i])///此步应该特别注意,要保证k/cost[i]〈num[i]   即k的总值不能超过题里给出的范围
                    temp[k+j]+=c[j];
            }

            for(int ii=0;ii<=total;ii++){
                c[ii]=temp[ii];
                temp[ii]=0;
            }
        }
    for(int i=1;i<=total+1;i++)
    if(!c[i]){
        printf("%d\n",i);
        break;
    }
   }
   return 0;
}
时间: 2024-10-11 05:45:43

hdu 1085 给出数量限制的母函数问题 Holding Bin-Laden Captive!的相关文章

hdu 1085 Holding Bin-Laden Captive!(母函数)

http://acm.hdu.edu.cn/showproblem.php?pid=1085 题意:1元,2元,5元的硬币分别有num[1],num[2],num[3]个.问用这些硬币不能组合成的最小钱数. 继续母函数. 有两个注意的地方: 对c2[]初始化的同时也要对c1[]初始化. 最后枚举到sum+1,因为存在[1,sum]都可以凑成的可能,这时输出sum+1. #include <stdio.h> #include <iostream> #include <map&g

HDU 1085

想来想去都有bug 最后简单粗暴的一个一个来处理了 #include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #include<queue> #include<stack> #define mem(a,b) memset(a,b,sizeof(a)) #define ll __int64 #def

HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)

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 hi

HDU 1085 Holding Bin-Laden Captive! 活捉本拉登(AC代码)普通型母函数

题意:有面值分别为1.2.5的硬币,分别有num_1.num_2.num_5个,问不能组成的最小面值是多少?(0<=每种硬币个数<=1000,组成的面值>0) 思路:母函数解决.只有3个括号要作乘法,分别代表面值1.2.5所能组成的情况.需要两个数组,所能组成的最大值为num_1+2*num_2+5*num_5.如果在这个范围内都能组成,那么最小不能组成的面值为num_1+2*num_2+5*num_5+1.若没有1分钱的硬币,那么不能组成的肯定是1了. 数组的用法:ans[]保存第一个

hdu 1085 有num1个 1 ,num2个 2 ,num3个 5 (母函数)

有num1个 1 ,num2个 2 ,num3个 5问它们不能组成的最小正整数是谁 样例的母函数 (1+X)(1+X2)(1+X5+X10+X15)展开后 X4的系数为0 Sample Input1 1 30 0 0 Sample Output4 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <s

(母函数) hdu 1085

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16562    Accepted Submission(s): 7443 Problem Description We all know that Bin-Laden is a notorious terrorist, and he h

hdu 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): 16063    Accepted Submission(s): 7206 Problem Description We all know that Bin-Laden is a notorious terrorist, and he

HDU 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): 17653    Accepted Submission(s): 7902 Problem Description We all know that Bin-Laden is a notorious terrorist, and he h

HDU 1085 Holding Bin-Laden Captive!(母函数或背包DP)

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 23245    Accepted Submission(s): 10350 Problem Description We all know that Bin-Laden is a notorious terrorist, and he