http://acm.hdu.edu.cn/showproblem.php?pid=1398

Square Coins

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

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
 母函数.......
 #include<iostream>
using namespace std;
int main()
{
int n,i,j,k;
while(cin>>n,n)
{
int c1[]={},c2[]={};
for(j=;j<=n;j++)
{
c1[j]=;
}
for(i=;i*i<=n;i++)
{
for(j=;j<=n;j++)
{
for(k=;k+j<=n;k+=i*i)
{
c2[k+j]+=c1[j];
}
}
for(j=;j<=n;j++)
{
c1[j]=c2[j];
c2[j]=;
}
}
cout<<c1[n]<<endl;
}
return ;
}

HDUOJ ------1398的更多相关文章

  1. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

  2. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  3. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  4. hdu 1398 Square Coins(生成函数,完全背包)

    pid=1398">链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张. 给定一个值n(n<=300),求用上述货币能使价值 ...

  5. hdu-oj 1874 畅通工程续

    最短路基础 这个题目hdu-oj 1874可以用来练习最短路的一些算法. Dijkstra 无优化版本 #include<cstdio> #include<iostream> ...

  6. C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...

  7. C++版 - HDUoj 2010 3阶的水仙花数 - 牛客网

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - ...

  8. 【BZOJ 1398】 1398: Vijos1382寻找主人 Necklace (最小表示法)

    1398: Vijos1382寻找主人 Necklace Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 308  Solved: 129 Descrip ...

  9. [hdu 1398]简单dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1398 看到网上的题解都是说母函数……为什么我觉得就是一个dp就好了,dp[i][j]表示只用前i种硬币 ...

随机推荐

  1. Andorid之使用GMail后台偷偷发送邮件(不要干坏事噢=。 =)

    工具类: import java.util.Date; import java.util.Properties; import javax.activation.CommandMap; import ...

  2. 解决kylin sync table报错:MetaException(message:java.lang.ClassNotFoundException Class org.apache.hive.hcatalog.data.JsonSerDe not found

    在kylin-gui中sync表default.customer_visit时报错: -- ::, ERROR [http-bio--exec-] controller.BasicController ...

  3. DIV元素不换行

    DIV盒子默认是换行独占100%宽度:DIV盒子没有赋予CSS样式时,默认DIV盒子是独占一行(宽度为100%). 如下默认情况HTML代码: <!DOCTYPE html> <ht ...

  4. (转载)ios的一些知识点

    ios的一些知识点 一 非ARC的内存管理情况  1-autorelease,当用户的代码在持续运行时,自动释放池是不会被销毁的,这段时间内用户可以安全地使用自动释放的对象.当用户的代码运行告一 段落 ...

  5. uva 10618 Tango Tango Insurrection 解题报告

    Tango Tango Insurrection Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebu ...

  6. 【面试必读】一不注意就做错的五道JavaScript题目

    如果不会,可以存在DW中运行试一下哦~ 1.这段代码会输出什么? function Container( properties ) { var objthis = this; for ( var i  ...

  7. OpenGL视图--gluPerspective glOrtho glFrustum gluLookAt

    void gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar ) near 和 far 决定了投 ...

  8. 【华为OJ平台练习题】求最大公共子串的个数和元素

    1.原题是求出最大公共子串的个数就可以 原理:利用二维矩阵排列的方式.将俩字符串进行比較 #include <iostream> #include <vector> using ...

  9. WPF DataTrigger的两个用法

    1.用在textbox等输入控件上,验证输入是否合法.首先定义一个Converter, 2.Xaml里面这样子写,意思是输入的数字,如果小于100则显示为红色. 3.combox等列表控件里面,也可以 ...

  10. SQL-查询排名

    select row_number() over(order by amount) as rank,* from dbo.t_group