首页 > 其他分享 >杭电1398

杭电1398

时间:2023-02-06 20:31:44浏览次数:38  
标签:square int coins 杭电 credit 1398 c2 c1


Square Coins

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


题意:火星上的货币有1,4,9,16,25…..2^17这17中面值的硬币,问任意给定一个不大于300的正整数面额,用这些硬币来组成此面额总共有多少种组合种数。
一看题目就确定是母函数问题


对应的母函数:
(1+x+x^2+x^3+…)(1+x^4+x^8+…..)(1+x^9+x^18)……………………….

代码1:

# include <iostream>

using namespace std;

int main(){

int n,i,j,k;
int c1[301],c2[301];

while(cin>>n,n!=0){

for(i=0;i<=n;i++){
c1[i] = 1;
c2[i] = 0;
}

for(i=2;i<=n;i++){//第i项
for(j=0;j<=n;j++){//i-1项符合条件的
//x^(k+j)<=x^n
for(k=0;k+j<=n;k+=i*i){//第i项的每一个数
c2[j+k] += c1[j];
}
}

for(k=0;k<=n;k++){
c1[k] = c2[k];
c2[k] = 0;
}
}

cout<<c1[n]<<endl;

}


return 0;
}

代码2:
# include <iostream>

using namespace std;

# define max 306

int c1[max],c2[max];
int main(){

int n,i,j,k;

for(i=0;i<=303;i++){
c1[i] = 1;
c2[i] = 0;
}

for(i=2;i<303;i++){
for(j=0;j<303;j++){
for(k=0;k+j<303;k+=i*i){
c2[j+k] += c1[j];
}
}

for(k=0;k<303;k++){
c1[k] = c2[k];
c2[k] = 0;
}
}

while(cin>>n,n!=0){
cout<<c1[n]<<endl;
}




return 0;
}


标签:square,int,coins,杭电,credit,1398,c2,c1
From: https://blog.51cto.com/u_15955675/6040465

相关文章

  • 杭电2073
    ​​http://acm.hdu.edu.cn/showproblem.php?pid=2073​​无限的路ProblemDescription甜甜从小就喜欢画图画,最近他买了一支智能画笔,由于刚刚接触,所以甜甜只会用它来画直......
  • 杭电2095(find your present (2))
    ​​这里写链接内容​​>引用块内容ProblemDescriptionInthenewyearparty,everybodywillgeta“specialpresent”.Nowit’syourturntogetyourspecialpre......
  • 1398:短信计费
    #include<iostream>usingnamespacestd;intmain(){ intn; cin>>n; floata,b=0; for(inti=0;i<n;i++){ cin>>a; if(a<70){ b=b+0.1; }else{ b=b+0.1; ......
  • 信奥赛 1398
    1398:短信计费时间限制:1000ms      内存限制:65536KB提交数:42379   通过数:19966【题目描述】用手机发短信,一条短信资费为0.1元,但限定一条短信......
  • C++ 1398:短信计费
    1398:短信计费【题目描述】用手机发短信,一条短信资费为0.1元,但限定一条短信的内容在70个字以内(包括70个字)。如果你一次所发送的短信超过了70个字,则会按照每70个字一条......
  • 整除的为数 杭电2099
    [1.(​​http://acm.hdu.edu.cn/showproblem.php?pid=2099%20%20%E9%97%AE%E9%A2%98%E9%93%BE%E6%8E%A5​​)]​​``这里写代码片​#include......
  • UVA1398 Meteor
    每颗流星经过框的时间用一个左开右开的开区间来表示,然后就是简单的求最大区间覆盖问题了。其中求开区间的方法很巧妙,可以节省一些代码量。#include<iostream>#include......
  • 2022 年杭电多校第六场 Multiply 2 Divide 2
    2022年杭电多校第六场Multiply2Divide2题意:BXY的序列\(a\)长度为\(n\)\((1\leqn\leq10^5,1\leqa_i\leq10^5)\)对于每个操作,他选择一个数字\(a_i(1\leqi\leqn......
  • 百度之星 初赛 A 杭电6376 度度熊剪纸条
    C度度熊剪纸条链接:​​​点我​​​ProblemDescription度度熊有一张纸条和一把剪刀。纸条上依次写着N个数字,数字只可能是0或者1。度度熊想在纸条上剪K刀(每一刀......
  • 2022 杭电杯(7) I Counting Good Arrays
    本题是2022CCPCF题的强化版.给出一个n,m求出所有长度小于等于n的数列\(a_k(k\len)\)且\(a_k\lem\)且\(a_i|a_{i+1}\)固定n显然可以发现对于m的标准分解\(m=p_1^{k......