HDU 1398 Square Coins
2015-03-14 21:24
435 查看
Square Coins
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8893 Accepted Submission(s): 6069
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 <iostream> #include <stdio.h> #include <string> #include <cstring> #include <cmath> #include <algorithm> #define N 1000 using namespace std; int n; int c1 ,c2 ; int a ; int main() { int num=0; for(int i=1;i<=300;i++) { for(int j=1;j<=50;j++) { if(j*j==i) a[num++]=i; } } // for(int i=0;i<num;i++) // cout<<a[i]<<" "; while(~scanf("%d",&n)) { if(n==0) break; memset(c1,0,sizeof c1); memset(c2,0,sizeof c2); c1[0]=1; for(int i=0;i<num;i++) { for(int j=0;j<=n;j++) { for(int k=0;k+j<=n;k+=a[i]) c2[j+k]+=c1[j]; } for(int j=0;j<=n;j++) { c1[j]=c2[j]; c2[j]=0; } } cout<<c1 <<endl; } return 0; }
相关文章推荐
- Square Coins hdu 1398
- hdu 1398 Square Coins/hdu 1028 Ignatius and the Princess III
- HDU 1398 Square coins 完全背包
- 母函数-以HDU-1398 Square Coins为例
- Square Coins HDU(1398)(典型的母函数)
- hdu1398 Square Coins ——DP
- hdu 1398 Square Coins
- HDU-1398-Square Coins
- Hdu 1398 Square Coins//整数划分(二)
- HDU 1398 Square Coins 平方硬币 (普通母函数,水)
- hdu 1398 Square Coins 完全背包变形
- hdu 1398 Square Coins
- 1398--Square Coins
- HDOJ-----1398---Square Coins---简单DP
- HDOJ HDU 1398 Square Coins ACM 1398 IN HDU
- HDU 母函数简单题 - 找单词/Ignatius and the Princess III/Square Coins/Holding Bin-Laden Captive!
- 杭电ACM hdu 1398 Square Coins 解题报告(母函数)
- HDOJ 1398 Square Coins解题报告
- HDOJ&nbsp;&nbsp;1398&nbsp;&nbsp;&nbsp;Square&nbsp;Coins
- Combinatorics——HDUOJ 1398 - Square Coins ! (母函数-种类个数无限)