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): 13861 Accepted Submission(s): 6230
“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!
1 1 3
0 0 0
4
题意:给定三中硬币,面值分别为1,2,5,而且给定三种硬币的数量分别为num_1,num_2,num_5,然后让求解这些硬币所不能组成的最小的面额是多少,比如给定的样例。面值为1的硬币为1枚,面值为2的硬币为1枚,面值为5的硬币为3枚,则能够组成的面值有1,2,3,5......所以,不能组成的最小面额为4。
这就是一道母函数的问题,可是这里并非求组合数。所以,不须要int行的数组来记录组合数,仅仅须要true和false来标示能否表示该面值就能够了。当然用int记录组合数也能够,但要注意。由于组合量很大,要注意溢出的情况,我试了一下能够,推断大于0的时候置1就能过。
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <algorithm> using namespace std; const int MAX = 8003;
const int type[3] = {1,2,5}; bool ans[MAX],tmp[MAX];
int cnt[3]; void work(){
int i,j,k; memset(ans,0,sizeof(ans));
memset(tmp,0,sizeof(tmp)); for(i=0;i<=cnt[0];++i){
ans[i] = true;
} //(author : CSDN iaccepted)
for(i=1;i<3;++i){
for(j=0;j<=MAX;++j){
for(k=0;k<=cnt[i] && j+k*type[i]<=MAX;++k){
//tmp[j+k*type[i]] += ans[j];
if(tmp[j+k*type[i]] || ans[j])tmp[j+k*type[i]] = true;
}
}
for(j=0;j<=MAX;++j){
ans[j] = tmp[j];
tmp[j] = false;
}
}
} int main(){
//freopen("in.txt","r",stdin);
//(author : CSDN iaccepted)
int res,i;
while(scanf("%d %d %d",&cnt[0],&cnt[1],&cnt[2])!=EOF){
if(cnt[0]==0 && cnt[1]==0 && cnt[2]==0)break;
work();
for(i=0;i<=MAX;++i){
if(!ans[i]){
res = i;
break;
}
}
printf("%d\n",res);
}
return 0;
}
HDU 1085 Holding Bin-Laden Captive! (母函数)的更多相关文章
- HDU 1085 Holding Bin-Laden Captive!(母函数,或者找规律)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)
Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...
- HDU 1085 Holding Bin-Laden Captive! 活捉本拉登(普通型母函数)
题意: 有面值分别为1.2.5的硬币,分别有num_1.num_2.num_5个,问不能组成的最小面值是多少?(0<=每种硬币个数<=1000,组成的面值>0) 思路: 母函数解决. ...
- hdu 1085 Holding Bin-Laden Captive! (母函数)
//给你面值为1,2,5的三种硬币固定的数目,求不能凑出的最小钱数 //G(x)=(1+x+...+x^num1)(1+x^2+...+x^2num2)(1+x^5+,,,+x^5num3), //展 ...
- 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, ...
- hdu 1085 Holding Bin-Laden Captive!
Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...
- HDU 1085 Holding Bin-Laden Captive --生成函数第一题
生成函数题. 题意:有币值1,2,5的硬币若干,问你最小的不能组成的币值为多少. 解法:写出生成函数: 然后求每项的系数即可. 因为三种硬币最多1000枚,1*1000+2*1000+5*1000=8 ...
- hdu 1085 给出数量限制的母函数问题 Holding Bin-Laden Captive!
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDOJ 1085 Holding Bin-Laden Captive! (母函数)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
随机推荐
- ViewPager实现页卡的3种方法(谷歌组件)
----方法一:---- 效果图: 须要的组件: ViewPager+PagerTabStrip 布局文件代码: <!--xmlns:android_custom="http://sc ...
- Java清洁:终结处理和垃圾回收
一般情况:Java有垃圾回收机制负责回收无用对象占据的内存资源. 特殊情况:假定你的对象(并非使用new)获得一块特殊的内存区域,由于垃圾回收器只知道释放那些经由new分配的内存,所以它不知道如何释放 ...
- C#获取文件和文件夹大小
代码如下: /// <summary> /// 获取文件夹大小 /// </summary> /// <param name="dirPath"> ...
- jquery之批量上传图片
//var btn; /** * * 获取当前时间 */ ==================================js=================================== ...
- C# 超级简单的Telnet (TcpClient)客户端
基于Sockets 没什么好说的,代码说明了所有 using System; using System.Collections.Generic; using System.Linq; using Sy ...
- 限制内容长度(CSS,jQuery)
CSS(宽度限制在100px之内,超出就会点点点) <style type="text/css"> p{width: 100px;display: inline-blo ...
- (转)Javascript 面向对象编程(一):封装(作者:阮一峰)
Javascript是一种基于对象(object-based)的语言,你遇到的所有东西几乎都是对象.但是,它又不是一种真正的面向对象编程(OOP)语言,因为它的语法中没有class(类). 那么,如果 ...
- 使用Dataset
string sqlStr="Select * from Tb_news"; SqlDataAdapter myDa=new SqlDataAdapter(SqlStr,myCon ...
- 线段树练习 codevs 1080
/* codevs 1080 线段树练习 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 一行N个方格,开 ...
- win8 Pro 64位在 UEFI模式下Ghost系统 备份 恢复
一:在win8 安装U 盘中 1. 新建 “Ghost” 文件夹 2. 将下载的Ghost64.exe 文件拷贝到文件夹 二: 启动的时候 按下F12 选择 HDDUSB 1.Windows 安装 ...