hdoj 1398 Square Coins
来源:互联网 发布:算法设计与分析电子书 编辑:程序博客网 时间:2024/06/05 17:23
Square Coins
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9923 Accepted Submission(s): 6803
Total Submission(s): 9923 Accepted Submission(s): 6803
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.
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
210300
Sample Output
1427
//次题所采用的多项式相乘的算法是先以第一个表达式的变量去遍历第二个表达式的变量 #include <stdio.h>#include<string.h>#define N 1010 int main(){ int i,j,k; int c1[N],c2[N];//k代表指数,c1表示系数,c2做中间过度的变量 int n; while(scanf("%d",&n)!=EOF&&n) { for(i=0;i<=n;i++)//初始化c1为1,代表第一个表达式的各个变量的系数皆为1 { c1[i]=1; c2[i]=0; } for(i=2;i<=17;i++) //从第二个表达式开始,题目平方 数最大为17 { for(j=0;j<=n;j++)//J表示进行一次表达式相乘后,第一个表达式的的第J个变量 for(k=0;k+j<=n;k+=i*i)// 此处表示第一个表达式的第J个变量遍历第二个表达式 (逻辑上的第I个表达式) { c2[j+k]+=c1[j];//C1[j]存储的是上一次运算结束后一个表达式中指数为j的系数,因为此时的第二个表达式的所有的系数均为1,其实就是将便利的过程中的拥有k+j指数的系数加1 } for(k=0;k<=n;k++) { c1[k]=c2[k];//将c2 存储的系数赋值给相应的c1,然后清零c2, c2[k]=0; } } printf("%d\n",c1[n]); } return 0;}母函数在知识点:http://blog.csdn.net/zhangxiaoxiang123/article/details/48429459
0 0
- hdoj 1398 Square Coins
- hdoj 1398 Square Coins
- HDOJ 1398 Square Coins
- HDOJ 1398 Square Coins
- hdoj-1398-Square Coins
- HDOJ 1398 Square Coins解题报告
- HDU/HDOJ 1398 Square Coins 母函数
- hdoj 1398 Square Coins(母函数)
- 母函数之Square Coins hdoj 1398
- HDOJ-1398-Square Coins 解题报告
- HDOJ Square Coins 1398【母函数】
- hdoj--1398--Square Coins(母函数)
- hdoj 1398 Square Coins【母函数】
- HDOJ-1398 Square Coins(母函数)
- HDOJ--1398Square Coins!!母函数
- HDOJ Square Coins
- HDOJ 题目1398Square Coins(母函数)
- HDOJ 1398 Square Coins
- 【Linux网络编程】IP地址介绍
- POJ3602解题报告
- C/C++一些问题的理解
- 图片的alpha融合算法
- 欢迎使用CSDN-markdown编辑器
- hdoj 1398 Square Coins
- Nutch 2.3 源码分析
- C/C++语言中const的用法
- Physics2D 检测圆形区域内的所有碰撞器
- 硬币面值组合问题
- spark调度系列----1. spark stanalone模式下Master对worker上各个executor资源的分配
- C#使用DirectShow播放视频文件
- json遍历
- 使用javaMail发送 邮件需要jar包mail.jar 和 activtion.jar