「POJ3734」Blocks
题意
有n个盒子和红,蓝,绿,黄四种颜色。使用这四种颜色对盒子进行染色,其中红色和绿色的数量必须为偶数,询问方案数
Solution
易知此题可以用指数型生成函数解决
对于红色和绿色,其EGF为
Ge(x)=1+2!x2+4!x4+6!x6⋯=2ex+e−x
蓝色和黄色的EGF为
Ge(x)=1+2!x2+3!x3+4!x4⋯=ex
乘起来可得
(2ex+e−x)2∗e2x
=4e4x+2e2x+1
我们知道∑i=0∞i!kixi=ekx,n次项的系数为n!kn
忽略常数项,回带可得
4n!4n+2×2n
乘上阶乘即为答案
44n+2×2n
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
   | #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <cstring> #include <iostream> using namespace std; typedef long long ll;
  template <typename T>void read(T &t) { 	t=0;int f=0;char c=getchar(); 	while(!isdigit(c)){f|=c=='-';c=getchar();} 	while(isdigit(c)){t=t*10+c-'0';c=getchar();} 	if(f)t=-t; }
  const int mod=10007; int T; int n;
  int fastpow(int a,int b) { 	int re=1,base=a; 	while(b) 	{ 		if(b&1) 			re=re*base%mod; 		base=base*base%mod; 		b>>=1; 	} 	return re; }
  int main() { 	read(T); 	while(T--) 	{ 		read(n); 		printf("%d\n",(fastpow(4,n)+fastpow(2,n+1))%mod*fastpow(4,mod-2)%mod); 	} 	return 0; }
   |