题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1398
题目大意:硬币问题,套模板。。。
代码如下:
#include <stdio.h>
#include <string.h>
const int MAX=305;
int c1[MAX],c2[MAX];
int main()
{
int n;
while(scanf("%d",&n)&&n)
{
memset(c1,0,sizeof(c1));//呵呵,真无奈,数组都定义到主函数外面了,第一次还要初始化,要不就wa,求解释。。。
c1[0]=1;
for(int i=1; i<=17; i++)//循环每个因子
{
memset(c2,0,sizeof(c2));
for(int j=0; j*i*i<=n; j++)//每个因子的每一项
{
for(int k=0; k+j*i*i<=n; k++)//循环c1数组的每一项
c2[k+j*i*i] += c1[k];
}
memcpy(c1,c2,sizeof(c2));
}
printf("%d\n",c1[n]);
}
return 0;
}