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. PAT 乙级 1024

    题目 题目地址:PAT 乙级 1024 题解 模拟题,重点需要考虑到各种不同情况:简单来说一下: 因为输入格式固定,所以把不同的部分分别存储和处理可以在很大程度上简化运算:其中需要考虑最多的就是小数部 ...

  2. gravity 使用操作。

    gravity 使用操作.最近我司有一个比较奇葩的需求,我们的环境是主从,因为数据量较大会定期的删除数据,最近不行了,要求新建出来一个库 同步正事环境的数据,但是要剔除 delete ,drop,tr ...

  3. C语言:自己编写的简易ftp客户端,包含(列表,进入目录,上传文件,下载文件,删除文件)功能

    //简易ftp客户端#include <stdio.h> #include <string.h> #include <sys/types.h> #include & ...

  4. JavaScript 基础语法

    1 谈谈 JavaScript JavaScript,通常会简称为'JS', 是一种浏览器脚本语言 1.1 JavaScript 编程语言特点 JavaScript是一种脚本编程语言 JavaScri ...

  5. Python知识点进阶——迭代器

    可迭代对象 可迭代对象可以简单的理解为用for循环遍历的,如list.tuple.dict.set.str 判断一个对象是否是迭代器: 可以将数据类型 和 是否为可迭代对象 比较来判断是否是可以迭代 ...

  6. Database returned an invalid datetime value. Are time zone definitions for your database installed?

    在做文章归档的会后,打印结果时报了这个错误 ret = models.Article.objects.filter(user=user).annotate(month=TruncMonth('crea ...

  7. 802. Find Eventual Safe States

    https://leetcode.com/problems/find-eventual-safe-states/description/ class Solution { public: vector ...

  8. Linux安全层详解

    1 bastion(安全堡垒系统)通常配置两个服务: 1 服务定义系统的功能: 2 服务支持远程访问: 原则: 1 不需要某个软件卸载掉: 2 需要某个软件但不使用就不要激活: 为各个bastion系 ...

  9. Selenium与PhantomJS【转】

    爬虫(Spider),反爬虫(Anti-Spider),反反爬虫(Anti-Anti-Spider) 之间恢宏壮阔的斗争... Day 1 小莫想要某站上所有的电影,写了标准的爬虫(基于HttpCli ...

  10. 第八届蓝桥杯C/C++ B组省赛----分巧克力

    分巧克力 问题描述 儿童节那天有K位小朋友到小明家做客.小明拿出了珍藏的巧克力招待小朋友们. 小明一共有N块巧克力,其中第i块是Hi x Wi的方格组成的长方形. 为了公平起见,小明需要从这 N 块巧 ...