Square Coins

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

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 <cstdio>
#include <algorithm>
using namespace std;
int dp[18][310];//dp[a][b]表示当只有小于等于a*a的硬币面值时凑成b credic有多少种情况 int main()
{
for(int i=1;i<=300;i++)
dp[1][i]=1;
for(int i=1;i<=17;i++)
dp[i][0]=1;//b=0,这时等于0好像更合理,但是下面
//dp[i][j]+=dp[i-1][j-k*i*i];,当j==k*i*i,dp[i][j]应该加1,
//故令dp[i][0]=1;
for(int i=2;i<=17;i++)
for(int j=1;j<=300;j++)
{
dp[i][j]=dp[i-1][j];
for(int k=1;j>=k*i*i;k++)
dp[i][j]+=dp[i-1][j-k*i*i];
} int n;
while(scanf("%d",&n),n)
printf("%d\n",dp[17][n]);
return 0;
}

hdu 1398 Square Coins(简单dp)的更多相关文章

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

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

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

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

  3. HDU 1398 Square Coins(DP)

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

  4. hdu 1398 Square Coins 分钱币问题

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

  5. hdu 1398 Square Coins (母函数)

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

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

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

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

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

  8. 杭电ACM hdu 1398 Square Coins

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

  9. HDU 1398 Square Coins

    题目大意:有面值分别为.1,4,9,.......17^2的硬币无数多个.问你组成面值为n的钱的方法数. 最简单的母函数模板题: #include <cstdio> #include &l ...

随机推荐

  1. 微软参考源代码 referencesource.microsoft.com

    微软参考源代码 http://referencesource.microsoft.com/ referencesource 下载地址 https://github.com/Microsoft/refe ...

  2. 可拖动FPS显示框(UGUI)

    简介 本来是想往上找一个可拖动FPS显示框的(我记得以前有人写过),然而搜了一个多小时都没搜到,索性自己写了一个,花费不到20分钟,看来还是自己动手丰衣足食啊 o(╯□╰)o 效果 上下的Toast不 ...

  3. wpf 下面用MVVC的RelayCommand命令引发的一个异常

    具体解决方法参见我的博问:https://q.cnblogs.com/list/myquestion

  4. Sql发布订阅设置不初始化订阅库架构的设置

    参考:http://www.cnblogs.com/TeyGao/p/3521231.html

  5. javascript:Bing Maps AJAX Control, Version 7.0

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. git 使用笔记(二)

    续 2.15 删除文件 $ rm testDel.txt删除掉工作区的testDel.txt文件, 1)这时可以通过git checkout -- testDel.txt从版本库恢复该文件到工作区 2 ...

  7. oGrid 介绍如何从 server 取的资料

    接着前次 oGrid 初探,其中有介绍如何操作local 资料,本次介绍如何从 server 取的资料. 依照 MVC 架构原理以及一条小龙本身经验来看,一个好的架构,必须要有着分工明确的设计层次,让 ...

  8. [C#]多线程下载

    发现电脑里以前编写的下载程序... 做个记录,那时做的挺匆忙的,没用委托,通过公开出窗体来修改下载进度,做的比较乱... ==!! 程序具体功能(流程): 1.检测系统托盘图标内的进程名是否符合要求 ...

  9. XML的介绍

    XML是指可扩展标记语言(eXtensible Markup Language),它是一种标记语言,类似于HTML.它被设计的宗旨是传输数据,而非显示数据.   XML标签没有被预定义,需要开发者自定 ...

  10. GTD3年来读的52本书

    2012年   1.一生的计划 平衡:人生要在精神.理财.教育和娱乐4个方面进行平衡.   2.重来REWORK 小型软件公司的创业与软件项目的管理 不要管全年计划,只要找出下一项最重要的任务,然后起 ...