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;
}

浙公网安备 33010602011771号