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 ...
随机推荐
- 用Turtle库画一个爱心
---恢复内容开始--- 用Python中的turtle库画一个爱心 这个学期,我学了Python语言,并学到其中的一个库:turtle库.用turtle库可以画一些你想画的图片,所以我就想画一个爱心 ...
- 关于mysql 8.0.13zip包安装
mysql 8.0.13默认有一个data文件夹,这个文件夹得删了,不然安装服务时候会有日志文件提示报错: Failed to find valid data directory. Data Dict ...
- 18CCPC网赛A 贪心
Buy and Resell Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 深入解析Dropout
过拟合是深度神经网(DNN)中的一个常见问题:模型只学会在训练集上分类,这些年提出的许多过拟合问题的解决方案:其中dropout具有简单性并取得良好的结果: Dropout 上图为Dropout的可视 ...
- 广州Uber优步司机奖励政策(12月21日到12月27日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 关于iOS开发的各种证书
关于iOS开发的各种证书 最近在接推送服务的时候,被各种证书弄得不亦晕乎,这里记录一下一些基本的证书作用: 1. App IDs appID分明确的和通配的两种,如果要使用推送功能,只能用明确的. 2 ...
- rsync同步的艺术
转自:http://roclinux.cn/?p=2643 如果你是一位运维工程师,你很可能会面对几十台.几百台甚至上千台服务器,除了批量操作外,环境同步.数据同步也是必不可少的技能. 说到“同步”, ...
- Windows系统常用修复命令 无须重装系统
1.0 netsh int ipv4 reset 2.0 netsh winsock reset winsock是Windows网络编程接口,winsock工作在应用层,它提供与底层传输协议无关的高层 ...
- ThinkDev.Data更新日志
2013-09-29 10:001.重构Where.And.Or.Having.JoinTable代码,新增条件组合查询QueryGroup2.1.1.2.0 2013-09-04 09:001.修复 ...
- 【SpringCloud】 第十篇: 高可用的服务注册中心
前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...