Square Coins

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11690    Accepted Submission(s): 8007

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
 
Source
 
Recommend
Ignatius.L   |   We have carefully selected several similar problems for you:  1028 2152 2082 1709 2079 

题意:

给出17种数字,分别为$i^{2}$,每种数字有无穷个可以选择,问有多少种方法可以组合出n...

分析:

生成函数的系数...

代码:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
using namespace std; const int maxn=300+5; int n,a[maxn],b[maxn],tmp[maxn]; signed main(void){
while(scanf("%d",&n)&&n){
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
b[0]=1;
for(int i=1;i<=17;i++){
memset(a,0,sizeof(a));
memset(tmp,0,sizeof(tmp));
for(int j=0;i*i*j<=n;j++)
tmp[i*i*j]=1;
for(int j=0;j<=n;j++)
if(b[j])
for(int k=0;k<=n;k++)
if(tmp[k])
a[j+k]+=b[j];
memcpy(b,a,sizeof(b));
}
printf("%d\n",b[n]);
}
return 0;
}

  


By NeighThorn

HDOJ 1398 Square Coins的更多相关文章

  1. HDOJ 1398 Square Coins 母函数

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  2. hdu 1398 Square Coins 分钱币问题

    Square Coins Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  3. hdu 1398 Square Coins (母函数)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  4. hdu 1398 Square Coins(简单dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Pro ...

  5. HDU 1398 Square Coins 整数拆分变形 母函数

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

  6. 杭电ACM hdu 1398 Square Coins

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  7. HDU 1398 Square Coins(母函数或dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  8. 题解报告:hdu 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  9. HDU 1398 Square Coins(DP)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

随机推荐

  1. Vue入门之v-if的使用

    在vue中一些常用的指令都是v-这样的,v-if是vue的一个内部指令,常用于html中 代码 <!DOCTYPE html> html lang="en"> & ...

  2. python实现批量修改文件名

    import os def dele(): # 设置一个计数器 n=0 st = input('请输入你要删除的字符:') for i in f: b = f[n] if st in b: oldna ...

  3. Java Web 基础(一) 基于TCP的Socket网络编程

    一.Socket简单介绍 Socket通信作为Java网络通讯的基础内容,集中了异常.I/O流模式等众多知识点.学习Socket通信,既能够了解真正的网络通讯原理,也能够增强对I/O流模式的理解. 1 ...

  4. python3.7 random模块

    #!/usr/bin/env python __author__ = "lrtao2010" #python3.7 random模块 import random #随机模块 # r ...

  5. Xadmin后台管理系统搭建基于Django1.11.11+Python3.6

    安装python及Django百度即可 主要介绍Xadmin安装 访问地址:https://github.com/sshwsfc/xadmin  下载 安装好之后,将xamdin目录复制到项目 我放在 ...

  6. devicemaps_init(mdesc)

    devicemaps_init的参数为machine_desc结构体.以s3c6410为例,在arch/arm/mach-s3c64xx/mach-smdk6410.c中使用上述宏声明machine_ ...

  7. Kilani and the Game CodeForces - 1105D (bfs)

    Kilani is playing a game with his friends. This game can be represented as a grid of size n×mn×m, wh ...

  8. JS 对于回调函数的理解,和常见的使用场景应用,使用注意点

      很经常我们会遇到这样一种情况: 例如,你需要和其他人合作,别人提供数据,而你不需要关注别人获取或者构建数据的方式方法. 你只要对这个拿到的数据进行操作. 这样,就相当于我们提供一个外在的函数,别人 ...

  9. loj2062 [HAOI2016]地图

    ref #include <algorithm> #include <iostream> #include <cstdio> #include <cmath& ...

  10. 使用Fiddler对Android应用进行抓包

    1.  打开Fiddler软件,效果图如下: 2. 首先,确保安装 Fiddler 的电脑和你的手机在同一局域网内,因为Fiddler只是一个代理,需要将手机的代理指向 PC 机,不能互相访问是不行的 ...