当前位置:网站首页>数学知识:满足条件的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;
}
边栏推荐
- 那些一门心思研究自动化测试的人,后来怎样了?
- PHP array splicing MySQL in statement
- Compile and install oh my Zsh
- [Qt5 basics] random number display
- Visual studio 2019 Download
- MFC TCP通信服务端客户端Demo备忘vs2019
- gin_ gorm
- With regard to the white box test, you have to master these skills~
- Pre training / transfer learning of models
- 生意和投资的思考
猜你喜欢

Compile and install oh my Zsh

Institute of Microbiology, commonly used biochemical reactions in microbiological testing

一站式洞察行业热点,飞瓜数据B站新功能「流量大盘」上线!

What will Web3 bring in the future?

孙宇晨接受瑞士媒体Bilan采访:熊市不会持续太久

3500 word summary: a complete set of skills that a qualified software testing engineer needs to master

Understanding and application of Qt5 layout in creation

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

WIN11中MathType编辑中“打开数学输入面板”是灰色不可编辑

小程序中实现excel数据的批量导入
随机推荐
尝试新的可能
PHP array splicing MySQL in statement
未来的 Web3会带来什么?
Strictmode analysis activity leakage -strictmode principle (3)
The argument type 'function' can't be assigned to the parameter type 'void function()‘
数字IC设计流程总结
用 Flutter 的 Canvas 画点有趣的图形
二季度最后一天
[deepin] common sets
gin_gorm
Unknown database connection database error
Understanding and application of Qt5 layout in creation
What are the functions of soil microorganisms in microbial detection?
微生物安全与健康,什么是生物处理?
Mysql database foundation: process control
Pre training / transfer learning of models
[simulation] 922 Sort Array By Parity II
Zero of DC learning notes -- overview and basic process introduction
Use strictmode strictmode principle (1)
Visual studio 2019 Download