HDU-1398 Square Coins
来源:互联网 发布:linux 自启动 编辑:程序博客网 时间:2024/06/08 17:10
Square Coins
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12878 Accepted Submission(s): 8848
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<string>#include<stdio.h>#include<iostream>#include<string.h>#include<queue>#include<stack>#include<map>#include<set>#include<math.h>#include<algorithm>#include<string.h>using namespace std;int main(){ long long a[305]; long long b[305]; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); int i,j,k,p; a[0]=1; int c[17]={1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289},n; for(i=0;i<=16;i++) { for(j=0;j<=300;j++) { for(k=0;j+k*c[i]<=300;k++) { b[j+k*c[i]]+=a[j]; } } for(j=0;j<=300;j++) { a[j]=b[j]; b[j]=0; } } while(~scanf("%d",&n)&&n) { printf("%lld\n",a[n]); }}
阅读全文
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
- solidThinking.Click2Form.2017.1.0.Win64 1DVD
- C#中的委托与事件
- Android 获取控件的宽和高
- PTA 3.11表达式转换
- 【非技术面试】31道,不准备就会掉进坑的问题
- HDU-1398 Square Coins
- WebView的基本使用
- 正则表达式
- Oracle connect by的使用
- 一些博客
- oracle 重启与关闭
- Redis 学习(一)redis的安装
- LeetCode 394. Decode String
- Redis命令总结