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\n",sum);
23         for(int i=0;i<=sum+1;i++)
24             if(!a[i]){
25                 printf("%d\n",i);
26                 break;
27             }
28     }
29     return 0;
30 } 
时间: 2024-08-14 09:57:17

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 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

HDU ACM 1085 Holding Bin-Laden Captive! 母函数?

分析:这题可以用母函数做,但可以找到简单的规律. 1.若1的个数为0,则输出1: 2.若1的个数不为0,则从1到n1+2*n2的数都能拼成:接着,只需考虑5的个数,若n1+2*n2能到4以上,则在所有5的组合中,中间4个间隔可以由n1+2*n2 填充,这时总和为S,则1到S之间的数都可以组成: 3.若n1+2*n2不能达到4,则开始达到5之前就断开了不能到5,就不用再去组合5的个数了. #include<iostream> using namespace std; int main() { i

母函数 入门习题

HDU.1028.Ignatius and the Princess III(母函数) //0MS 1500K //母函数..背包.DP都行.. #include <cstdio> #include <cstring> typedef long long LL; const int N=122; int n,f[N],tmp[N]; int main() { while(~scanf("%d",&n)) { memset(f,0,sizeof f), f

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

《第25小时》电影台词

00:37:00 [Monty standing in the men's bathroom, talking to himself in a mirror with a "FUCK YOU" written on it]Monty Brogan: Well, fuck you, too. Fuck me, fuck you, fuck this whole city and everyone in it. Fuck the panhandlers, grubbing for mone