当前位置:网站首页>求组合数 AcWing 889. 满足条件的01序列
求组合数 AcWing 889. 满足条件的01序列
2022-07-05 06:16:00 【T_Y_F666】
求组合数 AcWing 889. 满足条件的01序列
原题链接
算法标签
组合数学 组合计数 卡特兰数 逆元 快速幂 费马小定理
思路
代码
#include<bits/stdc++.h>
#define int long long
#define abs fabs
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 100005, mod = 1e9+7;
int pr[N], st[N], s[N], cnt;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
int qmi(int a, int b, int p){
int ans=1;
while(b){
if(b&1){
ans=ans*a%p;
}
a=a*a%p;
b>>=1;
}
return ans;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read();
int res=1;
// Cn 2n
Rep(i, 2*n, n+1){
res=res*i%mod;
}
// / n + 1 % p 需求逆元
rep(i, 1, n+2){
res=res*qmi(i, mod-2, mod)%mod;
}
printf("%lld\n", res);
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
猜你喜欢
4. Object mapping Mapster
Is it impossible for lamda to wake up?
MySQL advanced part 1: View
Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
Leetcode array operation
MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理
博弈论 AcWing 894. 拆分-Nim游戏
Liunx starts redis
leetcode-6110:网格图中递增路径的数目
2021apmcm post game Summary - edge detection
随机推荐
高斯消元 AcWing 884. 高斯消元解异或线性方程组
C - XOR to all (binary topic)
Regulations for network security events of vocational group in 2022 Guizhou Vocational College skill competition
JS quickly converts JSON data into URL parameters
【Rust 笔记】14-集合(下)
1040 Longest Symmetric String
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
Sum of three terms (construction)
【Rust 笔记】17-并发(下)
How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
Doing SQL performance optimization is really eye-catching
liunx启动redis
[leetcode] day94 reshape matrix
Appium基础 — 使用Appium的第一个Demo
MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理
Leetcode-6109: number of people who know secrets
MIT-6874-Deep Learning in the Life Sciences Week 7
MySQL advanced part 2: optimizing SQL steps
Appium automation test foundation - Summary of appium test environment construction
Nested method, calculation attribute is not applicable, use methods