hdu 1398 Square Coins (母函数裸题)

http://acm.hdu.edu.cn/showproblem.php?pid=1398 题意:所有的货币都是平方数,比如1,4,9…问凑出n块钱有多少种办法。 思路:母函数。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年02月25日 星期四 22时15分31秒
 4File Name :code/hdu/1398.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=305;
34int a[N],tmp[N];
35int n;
36int main()
37{
38	#ifndef  ONLINE_JUDGE 
39	freopen("code/in.txt","r",stdin);
40  #endif
41
42	while (scanf("%d",&n)!=EOF&&n)
43	{
44	    for (int i = 0 ; i <=  n ;i++)
45	    {
46		a[i] = 1;
47		tmp[i] = 0 ;
48	    }
49
50	    for ( int i = 2 ; i*i <= n ; i ++)
51	    {
52		for ( int j = 0 ; j <= n ; j++)
53		{
54		    for ( int k = 0 ; k+j <= n ; k+=i*i)
55		    {
56			tmp[j+k] += a[j];
57		    }
58		}
59
60		for ( int j = 0 ; j <= n ;j++)
61		{
62		    a[j] = tmp[j];
63		    tmp[j] = 0 ;
64		}
65	    }
66
67	    printf("%d\n",a[n]);
68	}
69
70  #ifndef ONLINE_JUDGE  
71  fclose(stdin);
72  #endif
73    return 0;
74}