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

news/2024/7/3 4:34:08 标签: HDU 1085

题目:HDU-1085

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1085

题目:

Holding Bin-Laden Captive!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19057    Accepted Submission(s): 8478


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<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<cstdio>
using namespace std;
const int maxn= 10005;
int a[maxn],b[maxn];
int dir[3]={1,2,5},num[3];
int main(){
	while(cin>>num[0]>>num[1]>>num[2]){
		if(num[0]==0 && num[1]==0 && num[2]==0) break;
		for(int i=0;i<=num[0]+num[1]*2+num[2]*5;i++){
			a[i]=0;
			b[i]=0;
		}
		int t=0;
		for(int i=0;i<=num[0];i++) a[i]=1;
		for(int i=1;i<3;i++){
			t+=num[i-1]*dir[i-1];
			for(int j=0;j<=t;j++)            //可以思考一下这里为什么需要用一个t来存,每次循环t怎么变化,代表什么意思
				for(int k=0;k<=num[i]*dir[i];k+=dir[i]){
					b[j+k]+=a[j];
				}
			for(int j=0;j<=t+num[i]*dir[i];j++){
				a[j]=b[j];
				b[j]=0;
			}
		}
		int k=0;
		for(int i=0;i<=num[0]+num[1]*2+num[2]*5;i++)
			if(a[i]==0){
				k=1;
				cout<<i<<endl;
				break;
			}
		if(k==0)
			cout<<num[0]+num[1]*2+num[2]*5+1<<endl;
		
	}
	return 0;
}

好好学习,加油~


http://www.niftyadmin.cn/n/1306272.html

相关文章

WebService之CXF注解之一(封装类)

Teacher.java&#xff1a; /*** Title:Teacher.java* Package:com.you.model* Description:老师封装类* author:Youhaidong(游海东)* date:2014-5-5 下午11:03:13* version V1.0*/ package com.you.model;import java.io.Serializable;/*** 类功能说明* 类修改者 修改日期* 修改…

编程神书_向编程之神祈祷

编程神书Oh Almighty All-One (01), 全能的哦(01)&#xff0c; Grant me the courage to embrace and early adopt new cool technologies, the serenity to ignore distractions from new technology fads and the wisdom to tell the difference. 让我勇于接受和尽早采…

YSlow开发:自定义规则集

(This is part 3. See part one and part two.) (这是第3部分。请参见第1部分和第2部分。) There are two concepts to remember when working on your YSlow extensions and customizations: 在处理YSlow扩展和自定义项时&#xff0c;要记住两个概念&#xff1a; rules (or &q…

HDU 1171 Big Event in HDU

题目&#xff1a;HDU-1085 题目链接&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid1085 题目&#xff1a; Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 31958 Accepted Submi…

WebService之CXF注解之二(Service接口)

ITeacherService.java&#xff1a; /*** Title:ITeacherService.java* Package:com.you.service* Description:教师Service接口* author:Youhaidong(游海东)* date:2014-5-5 下午11:06:24* version V1.0*/ package com.you.service;import javax.jws.WebMethod; import javax.j…

HDU 1709 The Balance(母函数)

题目&#xff1a;HDU-1085 题目链接&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid1085 题目&#xff1a; The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7089 Accepted Submission(s…

httpwatch使用_使用JavaScript的HTTPWatch自动化

httpwatch使用背景(Background) HTTPWatch (automation)HTTPWatch (自动化)...with PHP (and again and again, and response) ...用PHP (一次又一次&#xff0c;和response )JavaScript shell scripting JavaScript Shell脚本I gave this short presentation at the recent Ya…

WebService之CXF注解之三(Service接口实现类)

ITeacherServiceImpl.java&#xff1a; /*** Title:ITeacherServiceImpl.java* Package:com.you.service.impl* Description:* author:Youhaidong(游海东)* date:2014-5-5 下午11:08:39* version V1.0*/ package com.you.service.impl;import com.you.model.Teacher; import co…