noip模拟赛#9 T3

都是套路QAQ

http://www.cnblogs.com/post/readauth?url=/Brian551/p/7571348.html

#include
#include
const int mod=1e8+7;
inline long long fast(long long a)
{
	long long ans=1;
	int b=mod-2;
	while(b)
	{
		if(b&1)	ans=(ans*a)%mod;
		a=(a*a)%mod;	
		b=b>>1;
	}
	return ans;
}
long long ans[300017];
inline long long calc(int n,int m)
{
	return ans[n]*fast(ans[m])%mod*fast(ans[n-m])%mod;
}
int main()
{
	freopen("path.in","r",stdin);
	freopen("path.out","w",stdout);
	int m,n,p,q;
	scanf("%d %d %d %d",&m,&n,&p,&q);
	int max=m>n?m:n;
	ans[0]=1;	
	for(int i=1;i<=3*max;i++)	ans[i]=(ans[i-1]*i)%mod;
	printf("%lld\n",( ( (calc(m+n,n)*calc(m-p+q,q)%mod) - (calc(m+q,q)*calc(m-p+n,n)%mod) )%mod+mod)%mod);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


你可能感兴趣的:(————杂七杂八————)