HDU 2069 母函数

news/2024/7/7 15:36:00 标签: php

/*

注意题目要求,

1,输入0,结果1

2,方案中硬币不超过100;

与hdoj 1028不同在于有限定100,数组需要多加一维;

*/

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

#include <iostream>
#include <cstring> 
using namespace std;

int a[255][105],b[255][105];
int main()
{
    int n;
    int c[5] = {1,5,10,25,50};
    while(cin>>n)
    {
    	if(n==0)
    	{
	    	puts("1");
	    	continue;
	    }
	    memset(a,0,sizeof(a));
	    memset(b,0,sizeof(b));
        for(int i = 0; i <= min(n,100); i++)  //超过100的初始为0,否则初始化为1(存在面值1的硬币) 
        {
            a[i][i] = 1;
        }
        for(int i = 1; i <= 4; i++)  //控制硬币类型选择 
        {
        	//共五项,先将第一项和第二项乘得结果,在于第三项乘,得到结果乘第四项…… 
            for(int j = 0; j <= n; j++)    //枚举已知范围 (前面所有项结果项结果) 
            for(int k = 0; k+j <= n; k+=c[i])  //枚举新增范围(下一项 ) 
            {
            	for(int l = 0; l + k/c[i] <= 100; l++) // 硬币数量不超过100的选择 
            	{
	            	b[j+k][l+k/c[i]] += a[j][l];
	            }
            }
            for(int j = 0; j <= n; j++)    //重置 
            {
            	for(int k = 0; k <= 100; k++)
                {
                	a[j][k] = b[j][k];
					b[j][k] = 0;
                }	
            }
        }
        int sum = 0;
        for(int i = 0; i <= 100; i++)  //对不超过100硬币数的统计总和 
        	sum += a[n][i];
        cout<<sum<<endl;
    }
} 


转载于:https://www.cnblogs.com/i-fuqiang/archive/2013/03/02/3189548.html


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

相关文章

第07课 全屏模式支持

本文为系列文章第七篇&#xff0c;介绍如何在Silverlight 2中使用全屏模式。 实现全屏模式 全屏模式有时候是非常有用的&#xff0c;在Silverlight中&#xff0c;提供了很好的支持。实现起来也非常的简单&#xff0c;其实只有一行代码&#xff0c;编写一个简单的XAML。 <…

linux文件系统课设总结,操作系统课程设计报告:Linux二级文件系统设计.doc

操作系统课程设计报告&#xff1a;Linux二级文件系统设计专 业&#xff1a;计算机科学与技术学 号&#xff1a;********姓 名&#xff1a;***提交日期&#xff1a;2013-3-8【设计目的】(1)本实验的目的是通过一个简单多用户文件系统的设计&#xff0c;加深理解文件系统的内部功…

nyist 163 Phone List

Phone List 时间限制&#xff1a;1000 ms | 内存限制&#xff1a;65535 KB难度&#xff1a;4描述Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Lets say the phone catalogue listed these numbers…

第08课 使用样式封装控件观感

本文为系列文章第八篇&#xff0c;主要介绍在Silverlight中使用Style元素封装控件观感 Silverlight 支持一种 Style 机制&#xff0c;它允许我们把控件的属性值封装成可重用的资源。我们可以把这些样式声明保存在独立于页面的其他文件中&#xff0c;然后就可以在一个应用程序中…

iphone开发笔记目录

自学Iphone有段时间了&#xff0c;现把博客中iphone开发相关整理一下&#xff0c;方便后人查看&#xff1a; 1 hello world 1.1 第一iPhone程序-Hello World 1.2 IOS SDK介绍 1.3 修改iOS工程属性 2 ios UI基础 2.1 增强版Hello World 2.2 MVC设计模式 …

linux 使用ci框架,【原创】Linux PSCI框架

背景Read the fucking source code! --By 鲁迅A picture is worth a thousand words. --By 高尔基说明&#xff1a;Kernel版本&#xff1a;4.14ARM64处理器使用工具&#xff1a;Source Insight 3.5&#xff0c; Visio1. 介绍PSCI, Power State Coordination Interface&#xff…

对信号注册函数signal的理解1

signal函数的原型是&#xff1a; void (*signal(int signum, void (*handler)(int)))(int); 参数说明&#xff1a; signum&#xff1a;指定的信号 其中函数指针handler的取值&#xff1a; SIG_IGN 忽略该信号SIG_DFL 采用系统默认方式处理信号自定义的信号处理函数指针其中的参…

cd linux menu.lst,Windows 7 中使用 grldr + menu.lst 引導 linux系統和win7.

由 kisppuuyy 于 星期五, 02/05/2010 - 22:11 发表由于win7系統啟動的引導方式于xp系統不同, 通過反復試驗于網上搜索的多種方法,總算找到了下述辦法:使用 grldr menu.lst 引導 linux系統和win7.首選備份bcd(為此付出了多次重裝win7的慘痛代價...):/createstore 创建一个新的空…