HDU 1398 Square Coins(母函数模板题)
来源:互联网 发布:mysql安装详解 编辑:程序博客网 时间:2024/06/14 06:42
Square Coins
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7903 Accepted Submission(s): 5349
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.
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
210300
Sample Output
1427
#include <stdio.h>int main(){int a[310],b[310],i,j,k,n;while(~scanf("%d",&n),n){for(i=0;i<=n;i++){a[i]=1;b[i]=0;}for(i=2;i<=17;i++){for(j=0;j<=n;j++)for(k=0;k+j<=n;k+=i*i)//模板k+=i改成k+=i*ib[k+j]+=a[j];for(j=0;j<=n;j++){a[j]=b[j];b[j]=0;}}printf("%d\n",a[n]);}return 0;}/*#include <stdio.h>int ans[]={0,1,1,1,2,2,2,2,3,4,4,4,5,6,6,6,8,9,10,10,12,13,14,14,16,19,20,21,23,26,27,28,31,34,37,38,43,46,49,50,55,60,63,66,71,78,81,84,90,98,104,107,116,124,132,135,144,154,163,169,178,192,201,209,220,235,247,256,271,286,302,311,329,347,365,378,397,420,438,455,476,504,526,545,571,601,629,648,679,713,747,771,804,844,880,910,945,993,1035,1072,1116,1167,1216,1255,1306,1361,1420,1466,1525,1590,1653,1707,1770,1846,1916,1981,2055,2141,2222,2291,2374,2468,2563,2641,2737,2846,2952,3042,3145,3267,3385,3491,3607,3745,3880,3998,4130,4279,4431,4564,4714,4880,5050,5201,5368,5555,5742,5914,6101,6312,6521,6712,6921,7155,7389,7601,7834,8094,8355,8591,8849,9139,9431,9697,9984,10304,10628,10923,11238,11592,11953,12285,12637,13027,13424,13793,14180,14607,15048,15460,15895,16368,16853,17305,17782,18303,18835,19339,19867,20447,21031,21585,22161,22795,23441,24051,24694,25392,26109,26778,27482,28241,29025,29766,30535,31376,32235,33055,33896,34812,35750,36651,37581,38578,39614,40598,41621,42707,43835,44914,46030,47228,48452,49641,50856,52170,53503,54801,56133,57560,59027,60434,61894,63443,65049,66585,68174,69865,71604,73290,75005,76852,78741,80589,82465,84468,86529,88530,90578,92737,94987,97162,99397,101749,104180,106551,108963,111524,114146,116735,119360,122146,124997,127792,130643,133641,136742,139761,142864,146119,149482,152762,156106,159629,163250,166821,170432,174255,178180,182046,185960,190071,194315,198484,202729,207163,211756,216269,220852,225644,230580,235465,240408,245594,250916,256195,261537,267123,272865,278544,284316};int n;int main(){while(~scanf("%d", &n),n)printf("%d\n",ans[n]);}*/
0 0
- HDU 1398 Square Coins(母函数模板题)
- 动态规划:HDU-1398-Square Coins(母函数模板)
- hdu 1398 Square Coins (母函数)
- hdu 1398 Square Coins (母函数)
- hdu 1398 Square Coins(母函数)
- hdu-1398 Square Coins(母函数)
- HDU 1398 Square Coins(母函数)
- HDU -- 1398 Square Coins(母函数)
- hdu 1398 Square Coins (母函数)
- HDU 1398-Square Coins (母函数)
- hdu 1398 Square Coins(母函数)
- hdu 1398 Square Coins(母函数)
- HDU 1398 Square Coins (母函数)
- HDU 1398 Square Coins (母函数)
- HDU 1398 Square Coins(母函数)
- HDU - 1398 Square Coins(母函数)
- HDU:1398 Square Coins(母函数)
- HDU 1398 Square Coins(母函数)
- 只显示图片的中间部分
- 【Unity3D自学记录】用Unity3D发邮件(带附件)
- 最糟糕的编程面试题
- toggle(切换元素的可见状态)
- 为什么要用属性 C# .NET中的字段与属性_2
- HDU 1398 Square Coins(母函数模板题)
- JAVA之Class类与反射总结
- Python已成美国顶尖高校中最受欢迎的入门编程语言
- ZigBee四种绑定方式在TI Z-Stack中的应用【转载】i
- 冒泡排序
- 用Maven构建基于hadoop的Mahout项目
- kali linux安装qq2013
- VS2012中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法
- flex 的不定项参数实现