hdu 2069 母函数(一) 抑或 暴力枚举

hdu2069Coin Change 暴力/背包/母函数 Coin ChangeTime Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22298    Accepted Submission(s): 7801Problem DescriptionSuppose there are 5 types of ... 阅读详情

Coin Change

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6775    Accepted Submission(s): 2246


Problem Description
Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.

For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, or two 5-cent coins and one 1-cent coin, or one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways of making changes for 11 cents with the above coins. Note that we count that there is one way of making change for zero cent.

Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program should be able to handle up to 100 coins.
 

Input
The input file contains any number of lines, each one consisting of a number ( ≤250 ) for the amount of money in cents.
 

Output
For each input line, output a line containing the number of different ways of making changes with the above 5 types of coins.
 

Sample Input
11 26
 

Sample Output
4 13
 



先上暴力AC:


#include<iostream>
using namespace std;
int main(){
	int n,a,b,c,d,e;
	while(cin>>n){  
		int count=0;
	for(a=0;a<=n;a++){
		for(b=0;5*b<=n-a;b++){
			for(c=0;10*c<=n-a-5*b;c++){
				for(d=0;25*d<=n-a-5*b-10*c;d++){
					 e=n-a-5*b-10*c-25*d;          //这里的50分必须省去不必要的循环(否则超时) 存在的可否在于下面:
					if(e%50==0&&a+b+c+d+e/50<=100) //e%50==0 要么有50分刚好成n元 要么没有50分  * 别忘了50分的个数是 e/50 *

						count++;
					}
				}
			}
		}
	cout<<count<<endl;
	}
return 0;
}

下面是母函数的:

#include<iostream>
using namespace std;
	int c1[251][101],c2[251][101];
	int a[6]={0,1,5,10,25,50};
	int sum[251];
int main(){
	

	c1[0][0]=1;   
 /* 注意 这里的初始化替代了:
int n,a[5]={1,5,10,25,50},sum; 
    for(int i=0;i<=260;++i)
    for(int j=0;j<=101;++j) 
    {
        c1[i][j]=0;c2[i][j]=0;
    }
    for(int i=0;i<=100;++i)//用面值为1的硬币组成价值为i(不超过100) 
    {
            c1[i][i]=1;*/

        for(int i=1;i<=5;i++){
		for(int j=0;j<=250;j++){
			for(int k=0;k*a[i]+j<=250;k++){
				for(int t=0;k+t<=100;t++){//遍历c1的coin数量
					c2[k*a[i]+j][t+k]+=c1[j][t];
				}
			}
		}
		for(int i=0;i<251;i++){
			for(int j=0;j<101;j++){
				c1[i][j]=c2[i][j];
				c2[i][j]=0;
			}
		}
	}
	/*int n;
	while(cin>>n){
		int sum=0;
		for(int i=0;i<105;i++){
			sum+=c1[n][i];
		}
		cout<<sum<<endl;
	}
	*/
	 for ( int j = 0; j != 251; ++ j )
           {
                for ( int i = 0; i != 101; ++ i )
                {
                      sum[j] += c1[j][i] ;
                }
           }
           int N;
           while ( cin >> N )
           {
                  
                  cout << sum[N] << endl;
           }
return 0;
}



HDU2069 - Coin Change - 基础dp(经典硬币问题) Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) Problem Description Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to ... 阅读详情

相关推荐

汇川H5U搭配步进伺服电机使用CANopen通讯控制电机案例

摘要:本文介绍了基于汇川H5U PLC和STM4260B-CANopen-M步进伺服电机的控制系统搭建流程。主要内容包括:硬件准备(PLC、伺服电机、24V电源)、电机参数默认设置(地址1号、1M波特率)、使用AutoShop软件编写程序(配置CANopen参数、导入电机描述文件、设置PDO参数)以及功能块编程(使能控制、速度控制、绝对位置控制等)。通过查阅通讯手册完成各功能块参数配置,最终在主程序中调用功能块实现控制系统开发。该方案适用于需要精确运动控制的工业自动化场景。

m0_46512607的博客 1596

Coin Change HDU - 2069 (超详细题解)

文章目录1.题目2.题意3.解题思路4.代码 1.题目 Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money. For example, if we ...

林深不见鹿 的博客 2336

Julia Ann老司机管理系统

https://content.badgirlsusa.com/Julia_Ann-Sexy_Julia_Ann_Fucks_A_Lil_Elf's_Big_Cock_/Julia-Ann-Naughty-America-%E6%80%A7%E6%84%9F%E7%9A%84%E8%A3%98%E8%8E%89%E5%A9%AD%E5%AE%89%E4%BA%82%E6%90%9E-lil-%E7%B2%BE%E9%9D%88%E7%9A%84%E5%A4%A7%E5%85%AC%E9%9B%9E-2020

www_oracle_com的博客 22万+

Coin Change----------蛮力法

<br />第 2348 题  :  Coin Change【hdoj2069】<br />(时间限制为:500毫秒)<br /> Problem DescriptionSuppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.<br /><br />For exa

includeiostream123的专栏 1057

AI产品经理必备:Agent评测维度、指标与工程化落地指南

随着大模型从单轮问答走向复杂的Agent应用,如何科学地评测一个Agent是否真正“办成了事”,成为AI产品经理必须掌握的核心能力。与传统大模型评测关注回答质量不同,Agent评测需要综合评估任务规划、工具调用、多轮对话一致性以及失败自愈等行为。任务完成率与工具调用成功率是最关键的两个量化指标,同时还需关注延迟与Token成本等工程约束。在实际落地中,评测集的设计要覆盖业务主流程与边界场景,并通过批量回归测试与版本对比,为产品选型、算法迭代和上线决策提供数据支持。本文系统拆解了Agent评测的完整流程,帮助

weixin_29057163的博客 344

新手小白如何学习编程

学习目标推荐第一门语言优势网站 / APP 开发(前端)JavaScript浏览器原生支持,能快速做出可视化效果后端 / 服务器 / 数据分析Python语法简洁像英语,库多、应用广(入门友好)游戏开发先用电竞入门,再转专业引擎硬件 / 嵌入式(比如单片机)C 语言贴近硬件,行业标准办公自动化(Excel / 文档处理)Python快速解决重复工作(比如批量改文件)👉新手首选推荐。

2501_94331842的博客 2233

I - Coin Change

Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money. For example, if we have 11 cents, then we

Sinhaeng_Hhjian 468

hcaptcha逆向实战:从API解析到参数构造的完整链路

本文详细拆解了hcaptcha验证码的逆向实战流程,从环境准备、捕获API与版本号,到解析核心加密逻辑hsw.js,再到构造getcaptcha请求参数,最后完成验证提交。文章重点剖析了motionData、n、c等关键参数的获取与构造方法,为开发者模拟浏览器行为、实现自动化验证提供了清晰的完整链路指南。

ik678901的博客 629

hdu-2069(动态规划)

Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 23469    Accepted Submission(s): 8231 Problem Description Suppose there are 5 ty...

积少成多,水滴石穿 694

保姆级教程:在RV1126开发板上跑通YOLOv5口罩检测(从数据集到摄像头实时识别)

本文提供了一份详细的RV1126开发板部署YOLOv5口罩检测系统的全流程指南,涵盖数据集准备、模型训练优化、边缘部署及实时摄像头识别等关键步骤。重点解析了RV1126开发板的性能特征、YOLOv5模型训练调优技巧、RKNN模型转换量化策略,以及部署过程中的性能优化方案,帮助开发者高效实现边缘端目标检测应用。

weixin_27310985的博客 108

基于QT+Halcon实现线序识别

一、线序识别算法步骤。 1.按照检测区域m_pItem1的外接矩形(rtBount)的大小, 截取感兴趣区域图像hRoi。 2.把截取出来的感兴趣区域图像hRoi, 分离出R、G、B三个通道hRed、hGreen、hBlue。 3.把hRed、hGreen、hBlue三个通道转换成cielab颜色空间, 得到hChannelL、hChannelA、hChannelB三个颜色图。 4.设m_pItem1的宽为iItemW, 高为iItemH. 分别申请大小为iItemW的pSumL、pSumA、pSumB内

专注现代C++实战,从核心语法到高性能编程,助力开发者深入掌握系统级编程精髓。 1748

cccc第五次训练

这次的训练,看着看懂题了,可是真到写的时候又无从下手,,还是练得少啊。而且要挑会写的先写,,,, 这次从后往前写代码。。 K-CodeForces - 4A  One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest

g_y_t的博客 602

(五)C++自制植物大战僵尸游戏LoadingScene的实现讲解

游戏启动后就会立即切换到游戏加载场景中。只有游戏资源文件加载完成后,才能进入游戏。Loadingscene类继承Cocos2d-x中的Scene父类,表明Loadingscene是一个场景类。切换到LoadingScene场景中,首先会创建该场景,会调用函数,在该函数中调用自己定义的方法实现指定功能。代码文件的位置如下图所示。

尔灵尔亿的博客 2006

hdu2069Coin Change-母函数

hdu2069 错解 //忽略了所有硬币总数小于100的限制,导致方案数偏大 #include using namespace std; int main() { int c1[260],c2[260],i,j,num,sum,P[6]={0,1,5,10,25,50}; while(scanf("%d",&sum)!=EOF) { memset(c1,0,

Time flies 925

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDU - 2069 - Coin Change

HDU - 2069 - Coin Change 第一次了解暴力+打表 = = 确实很神奇 题目解题过程暴力枚举一开始把暴力枚举的层次搞反了,不出所料Wa了。。。 搞对就好啦!暴力打表看到居然有人直接打表完放到一个数组里,,不过确实好机智呀,代码运行还很快!Ac代码还是先把才开始错误的贴一下吧// 2069 - Coin Changeint main() { int n, sum;

尧子的博客 491

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

hdu2069 暴力打表

http://acm.hdu.edu.cn/showproblem.php?pid=2069 暴力

x___song的专栏 462

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Coin Change(hdu2069,暴力or母函数)

http://acm.hdu.edu.cn/showproblem.php?pid=2069 Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10585    Accepted Submission(s)

JHC23的专栏 1753

HDU-2069 Coin Change (DP / 暴力枚举)

Coin Change Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 34020Accepted Submission(s): 12225 Problem Description Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1...

with_wine的博客 264

HDU 2069 Coin Change【带总数限制的母函数】

题目:http://acm.hdu.edu.cn/showproblem.php?pid=2069 因为母函数的话 #include int main(){ int i,j,k,l,m,n; int count[251]={0}; for(n=0;n<=250;n++) for(j=0;j*5<=n;j++) for(k=0;k*10<=n;k++) f

某科学的程序员 651

HDOJ 2069 Coin Change

题意:有五种硬币,50元,25元,10元,5元,1元,并且不用超过100枚硬币,求n元能换成多少种不同的硬币 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 思路:暴力枚举 注意点:无 以下为AC代码: Run ID Submit Time Judge Status Pro.ID Exe.Time Ex

luminous11的专栏 525

【HDU】2069 - Coin Change(暴力)

点击打开题目 Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 17862    Accepted Submission(s): 6152 Problem Description

wyg1997 691

hdu 2069 Coin Change 解题报告

链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for ...

weixin_30399055的博客 130

Coin Change HDU - 2069

Coin Change HDU - 2069

kleefufu的博客 148

HDU 2069 Coin Change

Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 14228    Accepted Submission(s): 4764 Problem Description Suppose there

自己选择的路,就算跪着也要走完。 675

题解报告:hdu 2069 Coin Change(暴力orDP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coi...

weixin_30709061的博客 169

【HDU 2069】Coin Change 暴力枚举法

Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 18669    Accepted Submission(s): 6460 Problem Description Suppose there

逆风起飞 428
上一篇: hdu 2090 使用ctrl+z 两次结束循环
下一篇: 母函数 ~的母函数~~!!
AT
AT
博客等级 码龄15年 12粉丝 90原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值