bzoj1856 [Scoi2010]字符串

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

 

正解:组合数学。

裸卡特兰数。

 

 1 #include <bits/stdc++.h>
 2 #define il inline
 3 #define RG register
 4 #define ll long long
 5 #define rhl (20100403)
 6 #define N (2000010)
 7 
 8 using namespace std;
 9 
10 int inv[N],fac[N],ifac[N],n,m;
11 
12 il int C(RG int n,RG int m){
13   return 1LL*fac[n]*ifac[m]%rhl*ifac[n-m]%rhl;
14 }
15 
16 int main(){
17 #ifndef ONLINE_JUDGE
18   freopen("string.in","r",stdin);
19   freopen("string.out","w",stdout);
20 #endif
21   cin>>n>>m,fac[0]=ifac[0]=fac[1]=ifac[1]=inv[1]=1;
22   for (RG int i=2;i<=n+m;++i){
23     inv[i]=1LL*(rhl-rhl/i)*inv[rhl%i]%rhl;
24     fac[i]=1LL*fac[i-1]*i%rhl;
25     ifac[i]=1LL*ifac[i-1]*inv[i]%rhl;
26   }
27   printf("%d\n",(C(n+m,n)-C(n+m,n+1)+rhl)%rhl); return 0;
28 }

 

posted @ 2017-08-26 16:03  wfj_2048  阅读(179)  评论(0编辑  收藏  举报