版权声明:写得不好,转载请通知一声,还请注明出处,感激不尽 https://blog.csdn.net/As_A_Kid/article/details/85766917
Problem
BZOJ
Solution
我们去构造各个物品的生成函数
f1(x)=1−x21
f2(x)=1+x
f3(x)=1+x+x2
f4(x)=1−x2x
f5(x)=1−x41
f6(x)=1+x+x2+x3=(x+1)(x2+1)
f7(x)=1+x
f8(x)=1−x31
乘积为
x(1−x)−4
xi=0∑∞(i−4)(−x)i
第
n项系数就是求后面求和式子中的
n−1项,即
(−1)n−1(n−1−4)=(−1)n−1(n−1)!(−4)n−1
我们对
n−1的奇偶性分类讨论,容易知道肯定是一个正数,那么直接去掉所有负号,再改一下上升幂的表现方法即可得到
(n−1)!(4n−1)=(n−1)!An+2n−1=(n−1n+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;
}