ZOJ 1666 G-Square Coins
https://vjudge.net/contest/67836#problem/G
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 <bits/stdc++.h>
using namespace std; int coin[20] = {1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289};
int a[333][333];
int money; int main() {
while(~scanf("%d", &money)) {
memset(a, 0, sizeof(a));
if(money == 0)
break;
a[0][0] = 1;
for(int i = 0; i < 17; i ++) {
for(int j = coin[i]; j <= money; j ++) {
for(int k = 1; k < 300; k ++) {
if(j >= coin[i])
a[k][j] += a[k - 1][j - coin[i]];
}
}
} int sum = 0;
for(int i = 0; i < 300; i ++)
sum += a[i][money]; printf("%d\n", sum);
}
return 0;
}
ZOJ 1666 G-Square Coins的更多相关文章
- hdu 1398 Square Coins (母函数)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDOJ 1398 Square Coins 母函数
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- 题解报告:hdu 1398 Square Coins(母函数或dp)
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
- hdu 1398 Square Coins(简单dp)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Pro ...
- Square Coins[HDU1398]
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Square Coins(母函数)
Square Coins 点我 Problem Description People in Silverland use square coins. Not only they have square ...
- HDU1398 Square Coins(生成函数)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- HDU 1398 Square Coins 整数拆分变形 母函数
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
- HDU1398 Square Coins
Description People in Silverland use square coins. Not only they have square shapes but also their v ...
随机推荐
- 迪米特法则(LoD)
如果两个类不必彼此直接通信,那么这两个类就不应当发生直接的相互作用.如果其中一个类需要调用另一个类的某一个方法的话,可以通过第三者转发这个调用.其根本思想是类之间的松耦合. 类之间的耦合越弱,越有利于 ...
- HDFS重要特性
首先,它是一个文件系统,用于存储文件,通过统一的命名空间目录树来定位文件: 其次,它是分布式的,由很多服务器联合起来实现其功能,集群中的服务器有各自的角色. 1. master/slave 架构 HD ...
- 第6天 Java基础语法
第6天 Java基础语法 今日内容介绍 自定义类 ArrayList集合 引用数据类型(类) 引用数据类型分类 提到引用数据类型(类),其实我们对它并不陌生,如使用过的Scanner类.Random类 ...
- 【转载++】C/C++错误分析errno,perror,strerror和GetLastError()函数返回的错误代码的意义
本文是上一篇“fopen返回0(空指针NULL)且GetLastError是0”的侧面回应.听赶来多么地正确和不容置疑,返回NULL时调用GetLastError来看看报错啊,但当时却返回了0,大家都 ...
- C指针(4)——数据结构中指针的应用(非常重要)
5-1动态内存分配,分配的是堆内存的空间 分配内存函数 (都集中在库函数 stdlib.h 中) void *malloc (unsigned int num_bytes); //指定分配内存空间大 ...
- Emgucv安装及使用
Emgucv安装 最近有个客户联系我,希望我能够为他们做一个识别瓷砖花纹的软件.应用场景是这样的:现场会有一个摄像头去拍摄流水线上运输的瓷砖,如果检测这块瓷砖的花纹不符合要求,则需要给PLC或输出板卡 ...
- vue-router核心概念
vue用来实现SPA的插件 使用vue-router 1. 创建路由器: router/index.js new VueRouter({ routes: [ { // 一般路由 path: '/abo ...
- 20145202马超《java》【课堂实验】P98测试
当时在加水印所以没来得及提交,然而我回宿舍第一时间就提交了,希望老师额能够看到
- 深圳Uber司机本周(7.13-7.19凌晨4:00)的奖励政策
本周(7.13-7.19凌晨4:00)的奖励政策为: 佣金返还: 车费的20%适用于所有产品(不包括Tesla)无获取条件 翻倍补贴: 每周一到周四07:00-10:00/17:00-22:00:车费 ...
- C#如何使用反射实现通过字符串创建类
在做项目中碰到一个问题,就是如何在知道一个类的名字,如何创建这个类呢.做的一个小测试,直接贴代码了. using System; using System.Collections.Generic; u ...