当前位置:网站首页>数学知识:满足条件的01序列—求组合数
数学知识:满足条件的01序列—求组合数
2022-07-01 01:02:00 【奋斗吧!骚年!】
题目:AcWing 889. 满足条件的01序列
给定 n 个 0 和 n 个 1,它们将按照某种顺序排成长度为 2n 的序列,求它们能排列成的所有序列中,能够满足任意前缀序列中 0 的个数都不少于 1 的个数的序列有多少个。
输出的答案对 109+7 取模。
输入格式
共一行,包含整数 n。
输出格式
共一行,包含一个整数,表示答案。
数据范围
1≤n≤105
输入样例:
3
输出样例:
5
题目分析:
组合计数,卡特兰数
#include <iostream>
using namespace std;
typedef long long LL;
const int N = 100010,mod = 1e9+7;
int qmi(int a,int k,int p)
{
int res=1;
while(k)
{
if(k&1)res=(LL)res*a%p;
a=(LL)a*a%p;
k>>=1;
}
return res;
}
int main()
{
int n;
cin>>n;
int a=n*2,b=n;
int res=1;
for(int i=a;i>a-b;i--)res=(LL)res*i%mod;
for(int i=1;i<=b;i++)res=(LL)res*qmi(i,mod-2,mod)%mod;
res=(LL)res*qmi(n+1,mod-2,mod)%mod;
cout<<res<<endl;
return 0;
}
边栏推荐
- Pre training / transfer learning of models
- [queue] 933 Number of Recent Calls
- 使用 C# 创造 ASCII 艺术
- Strictmode analysis activity leakage -strictmode principle (3)
- Sécurité et santé microbiennes, qu'est - ce que le traitement biologique?
- 【Qt5-基础篇】随机数显示屏展示
- 日志 logrus第三方库的使用
- 45 year old programmer tells you: why do programmers want to change jobs? It's too true
- visual studio 2019 下载
- 软件测试的可持续发展,必须要学会敲代码?
猜你喜欢

QT5-布局在创作中的理解应用

Selenium经典面试题-多窗口切换解决方案

Basic knowledge II - Basic definitions related to sta

远程办公如何保持高效协同,实现项目稳定增长 |社区征文

3dsmax插件开发遍历节点对象和Object获取及INode变换矩阵说明

After working for 6 years, let's take stock of the golden rule of the workplace where workers mix up

1500w播放下还藏着什么热点?B站2个未来趋势你不得错过

"Open math input panel" in MathType editing in win11 is gray and cannot be edited

gin_gorm

农产品换房?“变相”购房补贴!
随机推荐
视频教程 | 长安链推出系列视频教程合集(入门)
Draw some interesting figures with flutter's canvas
一些本质的区别
[simulation] 922 Sort Array By Parity II
[stack] 921 Minimum Add to Make Parentheses Valid
日志 logrus第三方库的使用
PHP converts two-dimensional array elements into key value pairs
【队列】933. Number of Recent Calls
3dsmax plug-in development traversal node object and object acquisition and inode transformation matrix description
Unknown database connection database error
With regard to the white box test, you have to master these skills~
图的连通性基础
微生物安全与健康,什么是生物处理?
Strictmode analysis registration strictmode principle (4)
gin 配置文件
一站式洞察行业热点,飞瓜数据B站新功能「流量大盘」上线!
Sort custom function
微生物健康,食品微生物检测为什么很重要
Digital IC design process summary
Unknown database连接数据库错误