1856: [Scoi2010]字符串
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1389 Solved: 770
[ Submit][ Status][ Discuss]
Description
lxhgww最近接到了一个生成字符串的任务,任务需要他把n个1和m个0组成字符串,但是任务还要求在组成的字符串中,在任意的前k个字符中,1的个数不能少于0的个数。现在lxhgww想要知道满足要求的字符串共有多少个,聪明的程序员们,你们能帮助他吗?
Input
输入数据是一行,包括2个数字n和m
Output
输出数据是一行,包括1个数字,表示满足要求的字符串数目,这个数可能会很大,只需输出这个数除以20100403的余数
Sample Input
2 2
Sample Output
2
HINT
【数据范围】
对于30%的数据,保证1<=m<=n<=1000
对于100%的数据,保证1<=m<=n<=1000000
Source
题解:http://www.cnblogs.com/jianglangcaijin/p/3443689.html
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long
#define p 20100403
using namespace std;
int n,m;
LL fac[2000003];
LL quickpow(LL num,LL x)
{
LL base=num%p; LL ans=1;
while (x)
{
if (x&1) ans=(ans*base)%p;
base=(base*base)%p;
x>>=1;
}
return ans;
}
LL solve(LL n,LL m)
{
return fac[n]*quickpow(fac[m],p-2)%p*quickpow(fac[n-m],p-2)%p;
}
int main()
{
scanf("%d%d",&n,&m);
fac[0]=1;
for (int i=1;i<=n+m;i++) fac[i]=fac[i-1]*i%p;
LL t=solve(n+m,m)%p;
LL t1=solve(n+m,m-1)%p;
t-=t1;
printf("%I64d\n",(t%p+p)%p);
}