【bzoj3028】食物 母函数+乘法逆元

6 篇文章 0 订阅
4 篇文章 0 订阅

AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=3028

【题解】

这是一道很神的题,虽然代码很短。

首先由母函数易得:

=x0+x2+x4+=11x2=x1+x3+x5+=x1x2=x0+x3+x6+=11x3=x0+x4+x8+=11x4=x0+x1=1x21x=x0+x1=1x21x=x0+x1+x2=1x31x=x0+x1+x2+x3=1x41x

加起来就是

展开后的系数就是答案。

很多题解都没有说明具体求法,我这里说得详细一点:

根据麦克劳林公式:

  • formula

那么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;
}




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值