当前位置:网站首页>Mathematical knowledge: 01 sequence satisfying conditions - find combinatorial number

Mathematical knowledge: 01 sequence satisfying conditions - find combinatorial number

2022-07-01 01:39:00 Fight! Sao Nian!

subject :AcWing 889. Satisfied 01 Sequence
Given n individual 0 and n individual 1, They will be arranged in some order with a length of 2n Sequence , Find all the sequences they can be arranged into , Can satisfy any prefix sequence 0 The number of is no less than 1 How many are there in the sequence of the number of .

The output answer is right 109+7 modulus .

Input format
All in one line , Contains integers n.

Output format
All in one line , Contains an integer , Answer .

Data range
1≤n≤105

sample input :

3

sample output :

5

Topic analysis :
Combination count , Carter LAN number

#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;
}
原网站

版权声明
本文为[Fight! Sao Nian!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/182/202207010101518442.html