[组合数学 卡特兰数] BZOJ 1856 [Scoi2010]字符串

终于弄懂了Catalan数的另类通项的实际意义了:http://www.cnblogs.com/jianglangcaijin/p/3443689.html


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#define P 20100403
using namespace std;
typedef long long ll;

const int N=2000000;
ll fac[N+5],inv[N+5];
 
inline void Pre()
{
    fac[0]=1;
    for (int i=1;i<=N;i++)
        (fac[i]=fac[i-1]*i)%=P;
    inv[1]=1;
    for (int i=2;i<=N;i++)
        (inv[i]=(P-P/i)*inv[P%i])%=P;
    inv[0]=1;
    for (int i=1;i<=N;i++)
        (inv[i]*=inv[i-1])%=P;
}

inline ll C(ll n,ll m){
    return fac[n]*inv[m]%P*inv[n-m]%P;
}

ll n,m;

int main()
{
	freopen("t.in","r",stdin);
	freopen("t.out","w",stdout);
	Pre();
	cin>>n>>m;  
    cout<<(C(n+m,n)-C(n+m,n+1)+P)%P<<endl; 
    return 0;
}


你可能感兴趣的:([组合数学 卡特兰数] BZOJ 1856 [Scoi2010]字符串)