BZOJ3028 食物

版权声明:写得不好,转载请通知一声,还请注明出处,感激不尽 https://blog.csdn.net/As_A_Kid/article/details/85766917

Problem

BZOJ

Solution

我们去构造各个物品的生成函数
f 1 ( x ) = 1 1 x 2 f_1(x)=\frac {1} {1-x^2}

f 2 ( x ) = 1 + x f_2(x)=1+x

f 3 ( x ) = 1 + x + x 2 f_3(x)=1+x+x^2

f 4 ( x ) = x 1 x 2 f_4(x)=\frac {x} {1-x^2}

f 5 ( x ) = 1 1 x 4 f_5(x)=\frac {1} {1-x^4}

f 6 ( x ) = 1 + x + x 2 + x 3 = ( x + 1 ) ( x 2 + 1 ) f_6(x)=1+x+x^2+x^3=(x+1)(x^2+1)

f 7 ( x ) = 1 + x f_7(x)=1+x

f 8 ( x ) = 1 1 x 3 f_8(x)=\frac {1} {1-x^3}

乘积为
x ( 1 x ) 4 x(1-x)^{-4}

x i = 0 ( 4 i ) ( x ) i x\sum_{i=0}^\infty\binom {-4} i (-x)^{i}

n n 项系数就是求后面求和式子中的 n 1 n-1 项,即
( 1 ) n 1 ( 4 n 1 ) = ( 1 ) n 1 ( 4 ) n 1 ( n 1 ) ! (-1)^{n-1}\binom {-4} {n-1}=(-1)^{n-1}\frac {(-4)^{\underline {n-1}}} {(n-1)!}
我们对 n 1 n-1 的奇偶性分类讨论,容易知道肯定是一个正数,那么直接去掉所有负号,再改一下上升幂的表现方法即可得到
( 4 n 1 ) ( n 1 ) ! = A n + 2 n 1 ( n 1 ) ! = ( n + 2 n 1 ) = ( n + 2 3 ) \frac {(4^{\overline{n-1}})} {(n-1)!}=\frac {A_{n+2}^{n-1}} {(n-1)!}=\binom {n+2} {n-1}=\binom {n+2} {3}

Code

#include <cstdio>
using namespace std;
typedef long long ll;
const int mod=10007,inv6=1668;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=(x*10+ch-'0')%mod,ch=getchar();
    if(f) x=-x;
}
int n;
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	read(n);
	printf("%lld\n",(ll)n*(n+1)*(n+2)*inv6%mod);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/As_A_Kid/article/details/85766917