hdu 1398 母函数模板
来源:互联网 发布:sql数据库定时备份 编辑:程序博客网 时间:2024/05/21 09:41
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 <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 400;int num;int a[maxn],b[maxn];int v[18];int main(){ for(int i=1;i<=17;i++) v[i]=i*i; while(cin>>num&&num) {//初始化amemset(a,0,sizeof(a));a[0]=1;for (int i=1;i<=17;i++)//循环每个因子{ memset(b,0,sizeof(b)); for (int j=0;j*v[i]<=num;j++)//循环每个因子的每一项 for (int k=0;k+j*v[i]<=num;k++)//循环a的每个项 b[k+j*v[i]]+=a[k];//把结果加到对应位 memcpy(a,b,sizeof(b));//b赋值给a} cout<<a[num]<<endl;} return 0;}
- hdu 1398 母函数模板
- hdu 1028 母函数模板
- 母函数模板 HDU-1028
- 母函数模板 hdu 2082
- hdu 2082 母函数模板
- HDU 1398 Square Coins(母函数模板题)
- 动态规划:HDU-1398-Square Coins(母函数模板)
- hdu 2082(找单词)(母函数,模板)
- HDU 1085母函数模板题
- HDU 2082 母函数模板题
- HDU 2152 Fruit (母函数+模板)
- HDU 1536 SG函数模板
- Square Coins (HDU 1398) ———母函数模板详解
- HDU1171 Big Event in HDU,母函数,终极模板
- 一道母函数的模板题 (hdu 2082)
- hdu 2082 母函数模板的基本运用
- hdu 2082找单词 母函数入门模板
- HDU 1028 整数拆分 (母函数_模板|| 背包)
- swift3.0 获取键盘高度,并让UITextView自动随键盘上移
- 【经典例题】编写一个函数,求第n个斐波那契数
- Miller-Rabin随机性素数测试算法
- EXCEL排序 (sort)【HDU】-1862
- Xcode报编译器报错: linker command failed with exit code 1(use -v to see invocation)
- hdu 1398 母函数模板
- 《Java多线程编程核心技术》学习笔记-第一章
- 组合的递归与非递归
- Linux驱动开发---gpio和gpiod
- OpenCV图像处理--为图像添加Logo
- C++primer[习题][第一章][11-20]
- 西安集训第七天-----claris叫你常见的数据结构维护技巧
- 判断Socket断开连接
- session是什么时候创建的?