hdu 1398 Square Coins (母函数裸题)

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

/* ***********************************************
Author :111qqz
Created Time :2016年02月25日 星期四 22时15分31秒
File Name :code/hdu/1398.cpp
************************************************ */
 1#include <cstdio>
 2#include <cstring>
 3#include <iostream>
 4#include <algorithm>
 5#include <vector>
 6#include <queue>
 7#include <set>
 8#include <map>
 9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
 1using namespace std;
 2const double eps = 1E-8;
 3const int dx4[4]={1,0,0,-1};
 4const int dy4[4]={0,-1,1,0};
 5const int inf = 0x3f3f3f3f;
 6const int N=305;
 7int a[N],tmp[N];
 8int n;
 9int main()
10{
11	#ifndef  ONLINE_JUDGE 
12	freopen("code/in.txt","r",stdin);
13  #endif
1	while (scanf("%d",&n)!=EOF&&n)
2	{
3	    for (int i = 0 ; i <=  n ;i++)
4	    {
5		a[i] = 1;
6		tmp[i] = 0 ;
7	    }
1	    for ( int i = 2 ; i*i <= n ; i ++)
2	    {
3		for ( int j = 0 ; j <= n ; j++)
4		{
5		    for ( int k = 0 ; k+j <= n ; k+=i*i)
6		    {
7			tmp[j+k] += a[j];
8		    }
9		}
1		for ( int j = 0 ; j <= n ;j++)
2		{
3		    a[j] = tmp[j];
4		    tmp[j] = 0 ;
5		}
6	    }
	    printf("%d\n",a[n]);
	}
1  #ifndef ONLINE_JUDGE  
2  fclose(stdin);
3  #endif
4    return 0;
5}