排列组合 HDU - 1521 一句话区分指数型母函数和母函数就是 母函数是组合数,指数型母函数是排列数 #include<bits/stdc++.h> using namespace std; #define maxn 12 double ans[maxn],tp[maxn],inv[maxn]; int n,m,a[maxn]; void init() { inv[0]=1; for(int i=1; i<=11; i++) inv[i]=inv[i-1]*i; } int main…
方法一: DFS 方法二:生成函数 每个数可以重复一定次数,求排列组合数,这是裸的指数型生成函数: #include <bits/stdc++.h> using namespace std; ],c2[]; ]; ]; int main() { a[] = ; ; i<; i++) a[i] = a[i-]*i; int n,m; while(scanf("%d%d",&n,&m)!=EOF) { memset(c1,,sizeof(c1)); mem…
Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.QHand In HandOnline Acmers Forum |DiscussStatistical Charts Problem ArchiveRealtime Judge StatusAuthors Ranklist       C/C++/Java ExamsACM StepsGo to JobContest LiveCast…
给出我初学时看的文章:母函数(对于初学者的最容易理解的) 普通母函数--------->HDU - 1028 例题:若有1克.2克.3克.4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案?如何解决这个问题呢?考虑构造母函数.如果用x的指数表示称出的重量,则:    1个1克的砝码可以用函数1+x表示,    1个2克的砝码可以用函数1+x2表示,(x2表示x的2次方)    1个3克的砝码可以用函数1+x3表示,    1个4克的砝码可以用函数1+x4表示,(1+x)(1+x2)(1+x3…
#include<cstdio> #include<cstring> using namespace std; int n,m,jiecheng[11]; double a[12],b[12]; int main() { //freopen("hdu1521.in","r",stdin); int x; jiecheng[0]=1; for(int i=1;i<=10;++i) jiecheng[i]=jiecheng[i-1]*i;…
这种有限制的类棋盘着色问题一般可以用指数型母函数来解决,设Hn表示这样的着色数,首先H0=1,则Hn等于四个字母的(A,B,C,D)的多重集合的n排列数,其中每个字母的重数是无穷,且要求A,C出现的次数是偶数,因此,H0,H1,...Hn,...的指数生成函数是A,B,C,D因子的乘积: 用快速幂解决,只不过在HDU不能用long long解决,要用__int64. 代码: #include <iostream> #include <cstdio> #include <cst…
///hdu 1028 母函数 一个数有几种相加方式 #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #define INF 1000000009 using namespace std; ; int c1[_max], c2[_max]; int main() { int n,i,j,k; while(cin>>n) { ;i<=n;i…
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstring> typedef long long LL; LL ans[][]; LL n,anss; LL get(LL x,LL y) { ) return ans[x][y]; ) ; ; ans[x][y]=; LL i; ;i<=y;i++) ans[x][y]+=get(x-y,i); re…
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says. "The second problem is, given an positive integer N, we define an equation like this: N=a[1]+a[2…
题意: 有n种物品,并且知道每种物品的数量ki.要求从中选出m件物品的排数.         (全题文末) 知识点: 普通母函数 指数型母函数:(用来求解多重集的排列问题) n个元素,其中a1,a2,····,an互不相同,进行全排列,可得n!个不同的排列. 若其中某一元素ai重复了ni次,全排列出来必有重复元素,其中真正不同的排列数应为 ,即其重复度为ni! 同理a1重复了n1次,a2重复了n2次,····,ak重复了nk次,n1+n2+····+nk=n. 对于这样的n个元素进行全排列,可得…