跳过正文
  1. Posts/

hdu 1028 Ignatius and the Princess III(整数拆分,母函数模板题)

·2 分钟

http://acm.hdu.edu.cn/showproblem.php?pid=1028 题意:求整数拆分数。 思路:母函数模板题。关于母函数的学习:http://www.cnblogs.com/syxchina/archive/2011/07/07/2197205.html http://www.cppblog.com/tanky-woo/archive/2010/08/02/121969.html

具体解释见代码注释。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年02月25日 星期四 21时53分43秒
 4File Name :code/hdu/1028.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=125;
34int n;
35int a[N],tmp[N]; //a[i]表示每两个表达式运算时候的前一个表达式的x^i的系数,以及最后的表达式的x^i的系数
36		//tmp[i]是每次运算临时存储指数用
37int main()
38{
39	#ifndef  ONLINE_JUDGE
40	freopen("code/in.txt","r",stdin);
41  #endif
42
43	while (~scanf("%d",&n))         //第i个表达式的样子为:(1+x^i,+x^(2*i),....) 表示有一个i,两个i......
44	{
45	    for ( int i = 0 ; i <= n ; i++)  //所以指数都非负,所以最多有n个表达式对答案有贡献。
46	    {
47		a[i] = 1;
48		tmp[i] = 0 ;
49	    }
50//每次只考虑两个表达式的运算,把运算结果放在第一个表达式里。
51	    for ( int i = 2 ; i <= n ; i++)  //i表示第i个表达式
52	    {
53		for ( int j = 0 ; j <= n ; j++) //j表示第一个表达式的第j个变量
54		{
55		    for ( int k = 0 ; k+j<= n ; k+=i) //k表示第i个表达式的指数,0,i,2*i,3*i...
56		    {
57			tmp[j+k] += a[j];
58		    }
59		}
60
61		for ( int j = 0 ; j <= n ; j++)
62		{
63		    a[j] = tmp[j];
64		    tmp[j] = 0  ;
65		}
66	    }
67
68	//    for ( int i = 0 ; i <= n ; i++) cout<<"i:"<<i<<" "<<a[i]<<endl;
69
70	    printf("%d\n",a[n]);
71	}
72
73  #ifndef ONLINE_JUDGE
74  fclose(stdin);
75  #endif
76    return 0;
77}

相关文章

hdu 5145 NPY and girls

http://acm.hdu.edu.cn/showproblem.php?pid=5145 题意:有n个女孩,编号1..n,第i个女孩在第a[i]个教室,m次访问,每次访问编号[L,R]的女孩,处于同一个教室的女孩一次只能访问一个,问有多少种访问方案。两个不同的方案当且仅当访问的顺序有所不同。

codeforces #334 div 2 D.Moodular Arithmetic

http://codeforces.com/contest/604/problem/D 题意:一个恒等式 f(kx%p)=kf(x)%p ,k,p为常数,且满足x对于定义域为0..p-1的p的整数,值域也在0..p-1范围(不一定一一对应)。问满足题意的f有多少个。 思路: f(0)=0,对于其他的值,当f(x)确定时,f(kx%p)也随之确定,那么把kx%p看做新的x,f(kkx%p)也随之确定…相当于【1,p-1】被分为r个小环,确定每个环可以任选一个数字,ans=p^r。环的个数可以用dfs跑一遍得到r. 注意当k=1的时候是特殊情况,f(x)恒等于f(x)那么答案应该有p的p次方种。因为对于p个f(0..p-1),每一个都可以任意取p种值。

codeforces 569 D. Symmetric and Transitive (组合数学 第二类斯特林数 贝尔数)

D. Symmetric and Transitive time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Little Johnny has recently learned about set theory. Now he is studying binary relations. You’ve probably heard the term “equivalence relation”. These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.

贝尔数(集合的划分数目)

·2 分钟
http://baike.baidu.com/link?url=kw5Kxe3nSvRJR0TpJUpMrORcQL8fyZFpJlT9_o0RlGYOy0bKFobabPPSj3LxGfy7o1qGVycrYK4Iags3hMFq0a 在组合数合里,贝尔数给出了集合划分的数目,以数学家埃里克·坦普尔·贝尔(Eric Temple Bell)命名,是组合数学中的一组整数数列。[1] 以B0= B1=1为始, 首几项的贝尔数为:1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975, …(OEIS的A000110数列)