【BZOJ 1856】 [Scoi2010]字符串

题解大多网上有
给链接 http://blog.csdn.net/wzq_qwq/article/details/48706151

重点是 如何计算 这个组合数!

这里用到了 逆元 欧拉定理! 自行Google

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define MO 20100403
#define LL long long
LL n,m;
LL j[2000000+1],tot=0;
LL Inv(LL x,LL y)
{
	LL ans=1;
	while(y)
	{
		if(y&1) ans=(ans*x)%MO;
		x=(x*x)%MO;
		y>>=1;
	}
	return ans;
}
LL F(LL x,LL y)
{
	return ((j[x]*Inv(j[y],MO-2))%MO*Inv(j[x-y],MO-2))%MO;
}
int main()
{
	j[1]=1;
	for(LL i=2;i<=2000000;i++) j[i]=(j[i-1]*i)%MO;
	scanf("%lld %lld",&n,&m);
	printf("%lld",(F(n+m,n)-F(n+m,m-1)+MO)%MO);
	return 0;
}

原文地址:https://www.cnblogs.com/ofsxb/p/5121412.html