AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=3028
【题解】
这是一道很神的题,虽然代码很短。
首先由母函数易得:
汉堡蜜桃面包鸡块土豆可乐鸡腿包子=x0+x2+x4+⋯=11−x2=x1+x3+x5+⋯=x1−x2=x0+x3+x6+⋯=11−x3=x0+x4+x8+⋯=11−x4=x0+x1=1−x21−x=x0+x1=1−x21−x=x0+x1+x2=1−x31−x=x0+x1+x2+x3=1−x41−x
加起来就是
展开后的系数就是答案。
很多题解都没有说明具体求法,我这里说得详细一点:
根据麦克劳林公式:
那么n次项的系数就是f(n)(0)/n!
然后我们求出n阶导数,将0带入就得到答案(求导过程复杂,难以言表),答案是C[n+2][3]
即n(n+1)(n+2)/6
这里需要求6模10007的逆元,exdcd搞搞。。。
/************
bzoj 3028
by chty
2016.12.5
************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<algorithm>
using namespace std;
#define FILE "read"
const int mod=10007;
char ch[510];
int n;
void exgcd(int a,int b,int &x,int &y){
if(!b) {x=1; y=0; return;}
exgcd(b,a%b,x,y);
int t=x; x=y; y=t-a/b*y;
}
int main(){
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
scanf("%s",ch+1); int len=strlen(ch+1);
for(int i=1;i<=len;i++) n=(n*10+ch[i]-'0')%mod;
int x,y;
exgcd(6,mod,x,y);
x=((x%mod)+mod)%mod;
printf("%d\n",(((n*(n+1))%mod*(n+2))%mod*x)%mod);
return 0;
}