母函数简单应用

题目:

Square Coins

Problem Description
People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland.
There are four combinations of coins to pay ten credits:

ten 1-credit coins,
one 4-credit coin and six 1-credit coins,
two 4-credit coins and two 1-credit coins, and
one 9-credit coin and one 1-credit coin.

Your mission is to count the number of ways to pay a given amount using coins of Silverland.

Input
The input consists of lines each containing an integer meaning an amount to be paid, followed by a line containing a zero. You may assume that all the amounts are positive and less than 300.
Output
For each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output.
Sample Input
2
10
30
0

Sample Output
1
4
27
代码:
#include<stdio.h>

#define max 310int main(){    int coin[17] = {1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289}; //列出所有coin的面值    int n,i,j,k, an[max], bn[max]; //an[]记录结果,bn[]记录中间值    while(scanf("%d", &n) && n)    {        for(i = 0; i <= n; i ++) //赋初值        {            an[i] = 1;            bn[i] = 0;        }        for(j = 1; j < 17; j ++) //从1到289        {            for(i = 0; i <= n; i ++)            {                for(k = 0; k + i <= n; k += coin[j])                    bn[k + i] += an[i];            }            for(i = 0; i <= n; i ++)            {                an[i] = bn[i];                bn[i] = 0;            }        }        printf("%d\n", an[n]);    }    return 0;}

转载于:https://www.cnblogs.com/Mr_Lai/archive/2010/11/24/1886462.html

HDU 1398 Square Coins相关推荐

  1. hdu 1398 Square Coins/hdu 1028 Ignatius and the Princess III

    两道母函数的模板题: http://acm.hdu.edu.cn/showproblem.php?pid=1398 View Code #include<iostream>#include ...

  2. HDU 1398 Square Coins

    题目大意:有面值分别为.1,4,9,.......17^2的硬币无数多个.问你组成面值为n的钱的方法数. 最简单的母函数模板题: #include <cstdio> #include &l ...

  3. HDOJ 1398 Square Coins

    母函数"第一季",无压力AC~ View Code 1 //#include <fstream> 2 #include <iostream> 3 using ...

  4. 北邮OJ 2016 网预-Square Coins

    时间限制 1000 ms 内存限制 65536 KB 题目描述 Artoria, also known as Saber-chan, was born into a time of chaos and ...

  5. HDU 5985 Lucky Coins 数学

    Lucky Coins 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5985 Description Bob has collected a lot ...

  6. hdu 5079 Square

    http://acm.hdu.edu.cn/showproblem.php?pid=5079 题意: n*n网格,每个格子可以涂黑色或白色,有的格子必须涂黑色 问最大白色正方形边长分别为0,1,2,- ...

  7. hdu 5903 Square Distance

    这题题解dp不懂 因为不知道它怎么记录dp的答案的 字符串那么长 我是贪心过得,当时还被四个人hack,都没成功,hhhhh 大意就是优先从头取字典序小的字母,担也要让后面不管怎么取都合法 #incl ...

  8. HDU 1518 Square

    dfs+剪枝. AC代码例如以下: ///dfs+剪枝 62MS 300K#include<iostream> #include<cstring> #include<al ...

  9. 杭电OJ分类题目(1)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(1) HDU Introduction HDU ...

最新文章

  1. python 简易计算器(只能计算加减乘除和括号)
  2. 银行业数据中心性能测试的策略与实践(PPT)
  3. Algorithm之EM:Expectation Maximization简介、代码实现
  4. Linux——快照与克隆
  5. ios 获取一个枚举的所有值_Java enum枚举在实际项目中的常用方法
  6. 计算机基础——原码、反码、补码转换
  7. vs2012打包和部署程序成可安装安装包文件(InstallShield
  8. 通过ADO压缩数据库
  9. Spring boot (5):Spring data jpa 的使用
  10. python requests 提示警告 InsecureRequestWarning
  11. 新电脑怎么分盘_【磁盘分区教程】如何给电脑进行分区?
  12. android的CursorLoader用法小结
  13. 从错误中学习,如何配置iis?
  14. android hook 框架 ADBI 如何实现so注入
  15. 高德地图api中的adcode城市编码
  16. 0.99元用7天,金山云大米云主机给你这个机会!
  17. 微信公共号token验证失败解决办法之一
  18. 昊昊与他的第一台服务器的故事(一)
  19. 企业微信账号异常,解决攻略
  20. VB.net读取Outlook签名

热门文章

  1. mysql 安装在路由器_MySQL如何安装?安装MySQL数据库的三种方法
  2. jquery模拟虚拟键盘带中文拼音输入_线上中文教学,这些设备越早知道越早受益!...
  3. 计算机办公软件知识,计算机办公软件基础知识1
  4. 发牌游戏 java_解析扑克牌游戏发牌算法——java实现
  5. 青州市2021年高考成绩查询,2021年青州市高考状元名单资料,今年青州市高考状元多少分...
  6. joomla 3.6 mysql 版本_Joomla是否支持MariaDB数据库?
  7. element tree ui 全选_element UI tree 控件,点击父节点进行异步加载,异步加载的数据不能全选...
  8. 环回测试能够提供什么信息_X射线无损检测能够提供BGA焊点的重要信息
  9. node.js学习文档_学习NodeJs从每天一个小知识点开始
  10. python3怎么安装mysql_Python3.7安装mysqlclient