杭电 1085

Holding Bin-Laden Captive!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 14670    Accepted Submission(s): 6566

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

母函数的变形;求出来每个的种类数,存入数组中,之后再判断是否为零就行了,

当然也有个简单的办法,就是观察是否能够超出四,这样更简单,代码更短,但是,就是不太容易想得出来:

简单的方法的代码如下:

<span style="font-size:14px;">#include<stdio.h>
int main()
{
	int a,b,c;
	while(~scanf("%d%d%d",&a,&b,&c),a+b+c)
	{
		if(a==0)
		{
			printf("1\n");
		}
		else if(a+2*b<4)
		{
			printf("%d\n",a+b*2+1);
		}
		else
		printf("%d\n",a+2*b+5*c+1);
	}
	return 0;
}</span>

至于母函数的代码也贴出来如下:

<span style="font-size:14px;">#include<stdio.h>
int c1[10100],c2[10100];
int main()
{
	int i,j,a,b,c;

	while(~scanf("%d%d%d",&a,&b,&c),a+b+c)
	{
		int sum=a+b*2+c*5;
		for(i=0;i<=sum;i++)
		c1[i]=c2[i]=0;
		for(i=0;i<=a;i++)
		c1[i]=1;
		for(i=0;i<=a;i++)
		for(j=0;j<=2*b;j+=2)
			c2[i+j]+=c1[i];
		for(j=0;j<=sum;j++)
			c1[j]=c2[j],c2[j]=0;
		for(i=0;i<=a+2*b;i++)
		for(j=0;j<=5*c;j+=5)
			c2[i+j]+=c1[i];//起初在这个地方,将i写成了j结果wa了好几回
		for(j=0;j<=a+2*b+5*c;j++)
			c1[j]=c2[j],c2[j]=0;
		for(j=0;j<=sum;j++)
		{
			if(c1[j]==0)
			{
				printf("%d\n",j);
				break;
			}
		}
		if(j>=sum+1)
		printf("%d\n",j);
	}
	return 0;
}
</span>

杭电 1085

时间: 2024-11-03 05:39:50

杭电 1085的相关文章

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

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

杭电1085(多重背包求解)

题目: 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

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

杭电ACM题目分类

杭电ACM题目分类 基础题: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.1163.1164.1170.1194.1196. 1197.1201.1202.1205.1219.1234.123

【转】对于杭电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 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime

hdu 1016 Prime Ring Problem DFS解法 纪念我在杭电的第一百题

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29577    Accepted Submission(s): 13188 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

一个人的旅行 HDU杭电2066【dijkstra算法】

http://acm.hdu.edu.cn/showproblem.php?pid=2066 Problem Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景--草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上看海芋,去纽约纯粹看雪景,去巴黎喝咖啡写信,去北京探望孟姜女--眼看寒假就快到了,这么一大段时间,可不

杭电1162--Eddy&#39;s picture(Prim()算法)

Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8070    Accepted Submission(s): 4084 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to b