博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
7.3.3 Square Coins
阅读量:5329 次
发布时间:2019-06-14

本文共 2142 字,大约阅读时间需要 7 分钟。

Square Coins

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 50 Accepted Submission(s): 48
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
210300
 
Sample Output
1427

思路:

母函数

函数为 (1+x+x^2+x^3+..x^n)*(1+x^4+x^8+..+x^)*(1+x^9+x^18+x^27+..+)*(...)

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 9 const int maxn=310;10 int n,b[20],a[maxn];11 int c1[maxn],c2[maxn];12 13 void close()14 {15 exit(0);16 }17 18 19 void init()20 {21 for (int i=1;i<=17;i++)22 b[i]=i*i;23 while (scanf("%d",&n)!=EOF)24 {25 if (n==0) close();26 memset(c1,0,sizeof(c1));27 memset(c2,0,sizeof(c2));28 for (int i=0;i<=n;i++)29 c1[i]=1;30 for (int i=2;i<=17;i++)31 {32 if (b[i]>n) break;33 for (int j=0;j<=n;j++)34 {35 if (c1[j]==0) continue;36 for (int k=0;j+k<=n;k+=b[i])37 {38 c2[j+k]+=c1[j];39 }40 }41 for (int j=0;j<=n;j++)42 c1[j]=c2[j],c2[j]=0;43 }44 printf("%d\n",c1[n]);45 }46 }47 48 int main ()49 {50 init();51 close();52 return 0;53 }

 

转载于:https://www.cnblogs.com/cssystem/p/3212389.html

你可能感兴趣的文章
pycharm激活地址
查看>>
hdu 1207 四柱汉诺塔
查看>>
Vue 2.x + Webpack 3.x + Nodejs 多页面项目框架(上篇——纯前端多页面)
查看>>
display:none与visible:hidden的区别
查看>>
我的PHP学习之路
查看>>
【题解】luogu p2340 奶牛会展
查看>>
对PostgreSQL的 SPI_prepare 的理解。
查看>>
解决响应式布局下兼容性的问题
查看>>
京东静态网页练习记录
查看>>
使用DBCP连接池对连接进行管理
查看>>
【洛谷】【堆+模拟】P2278 操作系统
查看>>
hdu3307 欧拉函数
查看>>
Spring Bean InitializingBean和DisposableBean实例
查看>>
Solr4.8.0源码分析(5)之查询流程分析总述
查看>>
[Windows Server]安装系统显示“缺少计算机所需的介质驱动程序”解决方案
查看>>
[容斥][dp][快速幂] Jzoj P5862 孤独
查看>>
Lucene 学习之二:数值类型的索引和范围查询分析
查看>>
软件开发工作模型
查看>>
Java基础之字符串匹配大全
查看>>
面向对象
查看>>