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

如果你刚学母函数的话,那这道题可能会是你的一道坎,,不要怕,最好别看别人的代码和题解,,若这题自己想通了,我想对母函数的理解,会到下一个层次的,加油吧

代码:

#include <stdio.h>
#define MAX 10100

int main()
{
	int c1[MAX] , c2[MAX] ,num[5] , a[]={0,1,2,5};
	while(~scanf("%d%d%d",&num[1],&num[2],&num[3]) &&(num[1]||num[2]||num[3]))
	{
		int m = num[1]*a[1]+num[2]*a[2]+num[3]*a[3] ;
		for(int i = 0 ; i <= m ; ++i)
		{
			c1[i] = 1 ;
			c2[i] = 0 ;
		}
		c1[m+1] = 0 ;
		int  len = num[1]*a[1] ;
		for(int i = 2 ; i <= 3 ; ++i)
		{
			len += num[i]*a[i] ;
			for(int j = 0 ; j <= len-num[i]*a[i] ; j++)
			{
				for(int k = 0 ; k+j <= len; k+=a[i])
				{
					c2[j+k] += c1[j] ;
				}
			}
			for(int j = 0 ; j <= len ; ++j)
			{
				c1[j] = c2[j] ;
				c2[j] = 0 ;
			}
		}
		for(int i = 0 ; i < MAX ; ++i)
		{
			if(c1[i] == 0)
			{
				printf("%d\n",i);
				break ;
			}
		}
	}
	return 0 ;
}

与君共勉

时间: 2024-10-08 20:04:36

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

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 Holding Bin-Laden Captive!

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 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

HDU 1085 Holding Bin-Laden Captive!(DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1085 解题报告:有1,2,5三种面值的硬币,这三种硬币的数量分别是num_1,num_2,num_5,问你不能凑的钱的最小值是多少. DP,开一个这样的数组dp[i][3],然后dp[i][0]表示凑成 i 元钱需要dp[i][0]张1块的,需要dp[i][1]张两块的,dp[i][2]张5块的,然后依次往后递推,得到 i 的途径一共有三种,第一种是i-1加一张一块的,第二种是i-2加上1张两块的,

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

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 h