跳过正文
  1. Posts/

hdu 1398 Square Coins (母函数裸题)

·1 分钟

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}

相关文章

hdu 1171 Big Event in HDU (母函数,01背包)

·3 分钟
**Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 26534 Accepted Submission(s): 9332 ** Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don’t know that Computer College had ever been split into Computer College and Software College in 2002. The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).

bzoj 1604: [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居 (曼哈顿距离的转化【拆点】+set+并查集)

http://www.lydsy.com/JudgeOnline/problem.php?id=1604 题意:了解奶牛们的人都知道,奶牛喜欢成群结队.观察约翰的N(1≤N≤100000)只奶牛,你会发现她们已经结成了几个“群”.每只奶牛在吃草的时候有一个独一无二的位置坐标Xi,Yi(l≤Xi,Yi≤[1..10^9];Xi,Yi∈整数.当满足下列两个条件之一,两只奶牛i和j是属于同一个群的: 1.两只奶牛的曼哈顿距离不超过C(1≤C≤10^9),即lXi - xil+IYi - Yil≤C. 2.两只奶牛有共同的邻居.即,存在一只奶牛k,使i与k,j与k均同属一个群. 给出奶牛们的位置,请计算草原上有多少个牛群,以及最大的牛群里有多少奶牛