HDU 1398 Square Coins
来源:互联网 发布:网络防骗小常识 编辑:程序博客网 时间:2024/06/07 01:21
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.
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 <iostream>#include <stdio.h>#include <string>#include <cstring>#include <cmath>#include <algorithm>#define N 1000using namespace std;int n;int c1[N],c2[N];int a[N];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[n]<<endl; } return 0;}
0 0
- hdu 1398Square Coins
- hdu 1398 Square Coins
- Hdu 1398 - Square Coins
- hdu 1398 Square Coins
- hdu 1398 Square Coins
- hdu 1398 Square Coins
- Square Coins hdu 1398
- hdu 1398 Square Coins
- HDU 1398 Square Coins
- hdu 1398 Square Coins
- hdu 1398 Square Coins
- hdu-1398-Square Coins
- HDU 1398 Square Coins
- hdu 1398 Square Coins
- hdu 1398 Square Coins
- hdu-1398-Square Coins
- HDU-1398 Square Coins
- hdu 1398 Square Coins
- 1094. The Largest Generation (25) 此题和六度空间一个道理,记录BFS的层次
- iOS模拟器URLWithString The operation couldn't be completed. (Cocoa error 256.)
- 迷宫---DFS和BFS解法
- VS2012 Express编译log4cplus图文教程
- 2015 HNU warm up 12
- HDU 1398 Square Coins
- 最长公共子序列Common Subsequence POJ1458
- C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
- 关于oracle数据库忘记超级管理员密码的问题
- NYOJ---6(贪心)-题目---------------------------------喷水装置(一)
- Add Two Numbers
- Eclipse 编码自动补全功能
- MP4文件格式的解析,以及MP4文件的分割算法
- Android 屏幕点击手势判断