bzoj 1856: [Scoi2010]字符串 卡特兰数

1856: [Scoi2010]字符串

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 1458  Solved: 814
[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

 

详见http://www.cnblogs.com/ezyzy/p/6532599.html

证明一样

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #define ll long long
 6 #define N 2000005
 7 using namespace std;
 8 int n,m;
 9 int jie[N];
10 const int p = 20100403;
11 int pw(int x,int y)
12 {
13     ll lst=1;
14     while(y)
15     {
16         if(y&1)lst=lst*x%p;
17         y>>=1;
18         x=(1LL*x*x)%p;
19     }
20     return lst;
21 }
22 int main()
23 {
24     scanf("%d%d",&n,&m);
25     jie[0]=1;
26     for(int i=1;i<=n+m;i++)jie[i]=(1LL*jie[i-1]*i)%p;
27     ll ans=1LL*jie[n+m]*pw(jie[n],p-2)%p*pw(jie[m],p-2)%p-1LL*jie[n+m]*pw(jie[n+1],p-2)%p*pw(jie[m-1],p-2)%p;
28     ans=(ans+p)%p;
29     printf("%lld\n",ans);
30     return 0;
31 }

 

posted @ 2017-03-10 18:52  SD_le  阅读(240)  评论(0编辑  收藏  举报
重置按钮