BZOJ1856 [Scoi2010]字符串 数论

原文链接http://www.cnblogs.com/zhouzhendong/p/8084577.html


题目传送门 - BZOJ1856


题意概括

  找出由n个1,m个0组成的字符串,且任意前几个字符中1的个数不能比0的个数少,询问满足要求的字符串个数。


题解

  这位大佬写的好。

http://blog.csdn.net/wzq_qwq/article/details/48706151


代码

#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long LL;
const LL mod=20100403;
const int N=2000005;
int n,m;
LL fac[N];
LL Pow(LL x,LL y){
if (y==0)
return 1LL;
LL xx=Pow(x,y/2);
xx=xx*xx%mod;
if (y&1LL)
xx=xx*x%mod;
return xx;
}
LL Inv(LL x){
return Pow(x,mod-2);
}
LL C(LL n,LL m){
return fac[n]*Inv(fac[m])%mod*Inv(fac[n-m])%mod;
}
int main(){
scanf("%d%d",&n,&m);
fac[0]=1;
for (LL i=1;i<=n+m;i++)
fac[i]=fac[i-1]*i%mod;
printf("%lld",(C(n+m,m)-C(n+m,m-1)+mod)%mod);
return 0;
}

  

上一篇:初学ios遇到问题记录01


下一篇:oracle 存储过程调用方式