[BZOJ3028][生成函数]食物

版权声明:虽然博主很菜,但是还是请注明出处(我觉得应该没人偷我的博客) https://blog.csdn.net/qq_43346903/article/details/87925793

BZOJ3028

生成函数入门题:
对八个类型分别求生成函数:
A ( x ) = i = 0 + x 2 i = 1 1 x 2 A(x)=\sum_{i=0}^{+\infty}x^{2i}=\frac{1}{1-x^2}
B ( x ) = 1 + x B(x)=1+x
C ( x ) = 1 + x + x 2 C(x)=1+x+x^2
D ( x ) = i = 0 + x 2 i + 1 = x 1 x 2 D(x)=\sum_{i=0}^{+\infty}x^{2i+1}=\frac{x}{1-x^2}
E ( x ) = i = 0 + x 4 i = 1 1 x 4 E(x)=\sum_{i=0}^{+\infty}x^{4i}=\frac{1}{1-x^4}
F ( x ) = 1 + x + x 2 + x 3 F(x)=1+x+x^2+x^3
G ( x ) = 1 + x G(x)=1+x
H ( x ) = i = 0 + x 3 i = 1 1 x 3 H(x)=\sum_{i=0}^{+\infty}x^{3i}=\frac{1}{1-x^3}

用因式分解把八个生成函数的笛卡尔积求出即为 x ( 1 x ) 4 \frac{x}{(1-x)^4}

然后用泰勒展开/广义二项式定理推出第n项的系数为 n ( n + 1 ) ( n + 2 ) 6 \frac{n(n+1)(n+2)}{6}

Code:

#include<bits/stdc++.h>
#define mod 10007
using namespace std;
inline int read(){
	int res=0,f=1;char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') f=-f;ch=getchar();}
	while(isdigit(ch)) {res=((res<<1)+(res<<3)+(ch^48))%mod;ch=getchar();}
	return res*f;
}
int n;
int main(){
	n=read();
	cout<<n*(n+1)%mod*(n+2)%mod*1668%mod;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_43346903/article/details/87925793