Square Coins

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

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
 
 
题意是用平方数来构成一个数字,有多少种不同的组成方案 。
一开始想用以为,发现是有很多重复情况的。比如说10 = 1 + 9 = 9 + 1 是不太好维护的
 
二维的做法就是用dp[i][j] ..表示用前i个平方数(0<i<=17)组成数字j的方案数。
这样就保证了不重复计算了 。
 
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
using namespace std;
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define lr rt<<1
#define rr rt<<1|1
typedef long long LL;
typedef pair<int,int>pii;
#define X first
#define Y second
const int oo = 1e9+;
const double PI = acos(-1.0);
const double eps = 1e- ;
const int N = ;
const int mod = 1e9+;
LL dp[N][N];
int n ;
void init() {
dp[][] = ;
for( int i = ; i <= ; ++i ){
for( int j = ; j < N ; ++j ){
for( int k = ; k <= j ; k += i * i ){
dp[i][j] += dp[i-][j-k];
}
}
}
}
void Run() {
if( !n ) return ;
cout << dp[][n] << endl;
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
init(); while( cin >> n ) Run();
}

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) Pro ...

  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. 获取class的儿子,报错undefined

       var tds = document.getElementsByClassName("dv1")[0].children     console.log(tds) 因为cla ...

  2. python常用函数 T

    timedelta() timedelta方法可以表示一个时间段,并可以进行计算,而且可以直接对datetime计算. 例子: today() datetime的today函数可以表示现在的时间. 例 ...

  3. python常用函数 J

    (1)join(iterable)/(2) join(str, str) (1)join()连接字符串数组.(2)os.path.join()将多个路径组合后返回. 例子:

  4. 解决python中转化成json的方法不能序列化datetime类型数据(转)

    Python自带的json.dumps方法序列化数据时候如果格式化的数据中有datetime类型数据时候会提示错误TypeError: datetime.datetime(2012, 12, 12, ...

  5. QT的总结文章(转)

    ★了解Qt和C++的关系  ★掌握Qt的信号/槽机制的原理和使用方法  ★了解Qt的元对象系统  ★掌握Qt的架构  ★理解Qt的事件模型,掌握其使用的时机 信号与槽.元对象系统.事件模型是Qt机制的 ...

  6. python 文件单行循环读取的坑(一个程序中,文件默认只能按行循环读取一次,即使写到另一个循环里,它也只读取一次)

    本来写了一个程序,想获取a文件中有,但是b文件中没有的行: 想到的方法是:1.一行一行提取a文件中数据,然后用a文件中的每一行与b文件中的每一行比较, 2.如果找到相同行就继续查找a中的下一行,如果找 ...

  7. Kettle5.4.0 java.lang.OutOfMemoryError

    CPU: Intel i3 3.40GHz Memory : 8G Kettle默认配置 将MySQL上的一张29W条数据的表,通过Kettle增量抽取到Vertica数据库中,结果在排序这一步报内存 ...

  8. jquery对象中 “冒号” 详解

      冒号  可以理解为 “匹配” 或 “选取”的意思.   $(":button") 表示匹配所有的按钮.$("input:checked")表示匹配所有选中的 ...

  9. 【leetcode】1025. Divisor Game

    题目如下: Alice and Bob take turns playing a game, with Alice starting first. Initially, there is a numb ...

  10. boost Shared Memory

    Shared Memory Shared memory is typically the fastest form of interprocess communicatioin. It provide ...