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

题干:

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

题目大意:

给你cnt1个一元硬币,cnt2个两元硬币,cnt3个五元硬币,问不能凑出来的第一个面额是多少。

解题报告:

         母函数。

AC代码:

#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int a[8005],b[8005];//b是中间值 
int c[3];//1  2  5的数量
int d[3] = {1,2,5}; 
int n,m;
int main()
{int t;while(cin>>c[0]>>c[1]>>c[2]) {if(c[0] + c[1] + c[2] == 0) break;memset(a,0,sizeof a);memset(b,0,sizeof b);for(int i = 0; i<=c[0]; i++) {a[i]=1,b[i]=0;} int maxx = c[0] + c[1]*2 + c[2]*5;for(int i = 1; i<=2; i++) {for(int j = 0; j<=maxx; j++) {if(a[j]==0) continue;//剪枝 for(int k = 0; k<=c[i]; k++) {b[j+k*d[i]] += a[j];}}for(int j = 0; j<=maxx; j++) {a[j]=b[j];b[j]=0;}
//			for(int i = 0; i<=m; i++) printf("%d ",a[i]);
//			printf("\n");}int flag = 0;for(int i = 0; i<=maxx; i++) {if(a[i] == 0) {flag=1;printf("%d\n",i);break;}}if(flag ==0) printf("%d\n",maxx+1);}return 0;
}

稍微优化一点的代码:(但是还是15ms)

#include <iostream>
#include <cstring>
using namespace std;
int n[3],a[9000],b[9000],i,j,k,last,last2;
int v[3]={1,2,5};
int main()
{while ((cin>>n[0]>>n[1]>>n[2])&&(n[0]!=0||n[1]!=0|n[2]!=0)){a[0]=1;last=0;for (i=0;i<=2;i++){last2=last+n[i]*v[i];memset(b,0,sizeof(int)*(last2+1));for (j=0;j<=n[i];j++)for (k=0;k<=last;k++)b[k+j*v[i]]+=a[k];memcpy(a,b,sizeof(int)*(last2+1));last=last2;}for (i=0;i<=last;i++)if (a[i]==0)break;cout<<i<<endl;}return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441827.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

html text align属性,HTML canvas

实例在位置 150 创建一条红线。位置 150 是下面实例中定义的所有文本的锚点。请研究每种 textAlign 属性值的效果&#xff1a;YourbrowserdoesnotsupporttheHTML5canvastag.JavaScript&#xff1a;var cdocument.getElementById("myCanvas");var ctxc.getContext(&qu…

html超链接点不了_HTML、CSS、JS都有哪些区别?不看必悔

划重点HTML、CSS、及JS的区别有哪些&#xff1f;在日常学习中&#xff0c;html&#xff0c;css和js我们都学过&#xff0c;起初分不清这三者的区别和联系&#xff0c;随着知识的增长&#xff0c;有了一些体会。看一下这三项技术都是什么&#xff0c;能干什么&#xff1f;web前端…

【Codeforces - 378C】Maze(dfs,思维)

题干&#xff1a; Pavel loves grid mazes. A grid maze is an n  m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty…

2019游戏 f1_2019年F1中国大奖赛激情开跑,这款手游带你体验真实F1的魅力

不知不觉&#xff0c;F1中国大奖赛进入第16个年头。你是否还记得2018年的F1中国大奖赛&#xff0c;真是跌宕起伏&#xff0c;红牛队车手里卡多在第三次练习赛中爆缸&#xff0c;之后在车队技师的努力下才赶上排位赛&#xff0c;结果他在正赛时第6位发车&#xff0c;竟然超出对手…

html自定义字体demo,如何在HTML网站上安装自定义字体

是的&#xff0c;您可以使用名为 font-face的CSS功能。它只在CSS3中正式批准&#xff0c;但已经在CSS2中提出并实现&#xff0c;并且在IE中已经支持相当长的时间。你在CSS中声明它像这样&#xff1a;font-face { font-family: Delicious; src: url(Delicious-Roman.otf); }font…

【OpenJ_Bailian - 1258】【POJ - 1258】Agri-Net (最小生成树裸题)

题干&#xff1a; Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course. Farmer John ordered a high speed connection for his farm and is goin…

docker jenkins 公钥_代码自动发布docker(20.10.1)+k8s(1.20.1)

PaaS平台Docker版本(20.10.1) 2020-12-15 k8s版本(1.20.1) 2020-12-19代码托管&#xff1a;https://github.com/kubernetes/官方网址&#xff1a;https://kubernetes.io/pod--容器外壳service--不是真正的服务是iptables或ipvs中的规则先创建pod&#xff0c;后创建service…

【HDU - 1272】小希的迷宫 (并查集判环)

题干&#xff1a; 上次Gardon的迷宫城堡小希玩了很久&#xff08;见Problem B&#xff09;&#xff0c;现在她也想设计一个迷宫让Gardon来走。但是她设计迷宫的思路不一样&#xff0c;首先她认为所有的通道都应该是双向连通的&#xff0c;就是说如果有一个通道连通了房间A和B&…

东北育才高中2021年高考成绩查询,东北育才学校国际部2021年招生计划

学校每年的招生计划都会发生变化&#xff0c;并不是一成不变的&#xff0c;所以大家一定要时刻关注招生计划。在报考一所学校的时候&#xff0c;大家要有计划性的选择报考学校&#xff0c;要先去了解学校大概招收多少学生&#xff0c;这样大家在报考学校时候的才能更好地去选择…

html启动word程序,Word工具栏直接启动外部程序

Word工具栏直接启动外部程序互联网 发布时间&#xff1a;2008-10-06 15:13:37 作者&#xff1a;佚名 我要评论从Word工具栏中也能直接启动外部程序&#xff0c;这样操作起来非常方便。我们以从Word启动计算器举例说明。单击“工具”菜单下的“自定义”命令&#xff0c;打…

linux ip brd不一致_3 个方便的命令行网速度测试工具 | Linux 中国

用这三个开源工具检查你的互联网和局域网速度。-- Ben Nuttall能够验证网络连接速度使您可以控制计算机。使您可以在命令行中检查互联网和网络速度的三个开源工具是 Speedtest、Fast 和 iPerf。SpeedtestSpeedtest 是一个旧宠。它用 Python 实现&#xff0c;并打包在 Apt 中&am…

【HDU - 1266 】Reverse Number(模拟,数字分位数处理)

题干&#xff1a; Welcome to 20064 computer college programming contest! Specially, I give my best regards to all freshmen! You are the future of HDU ACM! And now, I must tell you that ACM problems are always not so easy, but, except this one... Ha-Ha! G…

语言nomogram校准曲线图_R语言实现Cox模型校准度曲线绘制

01研究背景这是关于cox模型的第二篇文章&#xff0c;上一篇文章分享了运用Lasso回归如何筛选变量&#xff0c;将筛选后的变量绘制Nomogram图&#xff0c;本章分享构建模型后&#xff0c;如何绘制校准曲线。cox模型的验证不同于Logistic回归&#xff0c;cox的结局包括时间和状态…

【HDU - 5744 】Keep On Movin (回文串性质,贪心思维,不是水题)

题干&#xff1a; Professor Zhang has kinds of characters and the quantity of the ii-th character is aiai. Professor Zhang wants to use all the characters build several palindromic strings. He also wants to maximize the length of the shortest palindromic s…

国开大学计算机应用基础作业二,国家开放大学《计算机应用基础》形考作业二答案解析 (2)...

.题目1在Word 2010中编辑文本时&#xff0c;编辑区显示的“网格线”在打印时( )出现在纸上。选择一项&#xff1a;A. 全部 B. 不会C. 一部分 D. 大部分 正确答案是&#xff1a;不会题目2Word 2010 处理的文档内容输出时与页面显示模式显示的( )。选择一项&#xff1a;A. 一部分…

转成数组_JavaScript之数组扁平化

今天给大家分享一下JavaScript的数组扁平化。1. 扁平化数组的扁平化&#xff0c;就是将一个嵌套多层的数组 array (嵌套可以是任何层数)转换为只有一层的数组。举个例子&#xff0c;假设有个名为 flatten 的函数可以做到数组扁平化&#xff0c;效果就会如下&#xff1a;知道了效…

【POJ - 2676】Sudoku (经典深搜,dfs数独)

题干&#xff1a; Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the Figure. In some of the cells are written decimal digits from 1 to 9. The other cells are empty. The goal is to fill…

计算机专业408题目结构,2019考研408计算机组成原理知识:计算机系统层次结构

计算机组成原理在408计算机综合考试中所占分值45分&#xff0c;说明是必考的重点内容&#xff0c;考生要在这部分多花时间复习。以下是新东方在线整理的的计算机组成原理知识&#xff0c;希望大家认真看。2019考研408计算机组成原理知识:计算机系统层次结构1. 计算机硬件的基本…

overleaf表格_latex 表格制作

在制作latex表格时遇到了以下问题&#xff1a;一、合并单元格包括多行合并、多列合并、多行多列同时合并。多行合并&#xff1a; \multirow{2}{*}{Multi-Row}多列合并&#xff1a; \multicolumn{2}{|c|}{Multi-Column}多行多列同时合并&#xff1a;\multicolumn{2}{|c|}{\multi…

【HihoCoder - 1268】九宫 (dfs,深搜)

题干&#xff1a; 小Hi最近在教邻居家的小朋友小学奥数&#xff0c;而最近正好讲述到了三阶幻方这个部分&#xff0c;三阶幻方指的是将1~9不重复的填入一个3*3的矩阵当中&#xff0c;使得每一行、每一列和每一条对角线的和都是相同的。 三阶幻方又被称作九宫格&#xff0c;在…