BZOJ3028 食物

Problem

BZOJ

Solution

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

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

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

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

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

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) f6(x)=1+x+x2+x3=(x+1)(x2+1)

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

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

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

x ∑ i = 0 ∞ ( − 4 i ) ( − x ) i x\sum_{i=0}^\infty\binom {-4} i (-x)^{i} xi=0(i4)(x)i

n n n项系数就是求后面求和式子中的 n − 1 n-1 n1项,即
( − 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)!} (1)n1(n14)=(1)n1(n1)!(4)n1
我们对 n − 1 n-1 n1的奇偶性分类讨论,容易知道肯定是一个正数,那么直接去掉所有负号,再改一下上升幂的表现方法即可得到
( 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} (n1)!(4n1)=(n1)!An+2n1=(n1n+2)=(3n+2)

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值