AcWing 889. 满足条件的01序列

求卡特兰数的模板
卡特兰数
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

const int N = 2e5+10,mod = 1e9+7;

int qpow(int a,int b,int p){
    int res=1;
    while(b){
        if(b&1) res=(LL)res*a%p;
        a=(LL)a*a%p;
        b>>=1;
    }
    return res;
}

int main(){
    int n;
    cin>>n;
    int res=1;
    for(int i=1,j=2*n;i<=n;i++,j--){
        res=(LL)res*j%mod;
        res=(LL)res*qpow(i,mod-2,mod)%mod;
    }
    res=(LL)res*qpow(n+1,mod-2,mod)%mod;
    cout<<res;
    return 0;
}

posted @ 2022-05-11 19:56  xhy666  阅读(38)  评论(0)    收藏  举报