AtCoder Regular Contest 110 E.Shorten ABC——坑

I
don’t know how to count. Probability and Mathematical Statistics in the next semester.

E.Shorten ABC

When the B array is determined, it is not difficult to find that the question asked is the number of plans for the A sequence selected from the B sequence.
It is equivalent to selecting s+n balls from m+n. We assume that the n balls of multiple selections are a partition, and the array A is separated. The partition of the multiple selection determines the ball in B The number (because most m) the
answer is C m + ns + n, s C_{m+n}^{s+n},sCm+ns+n,s is the total number of balls in array A.

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<random>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=200010;
const ll mod=1e9+7;
ll qmi(ll a,ll b,ll p)
{
    
    
    ll res=1;
    while(b)
    {
    
    
        if(b&1) res=res*a%p;
        b>>=1;
        a=a*a%p;
    }
    return res;
}
ll C(ll n,ll m)
{
    
    
    ll res=1;
    for(int i=1;i<=m;i++)
        res=res*qmi(i,mod-2,mod)%mod*(n-i+1)%mod;
    return res;
}
int main()
{
    
    
    IO;
    int T=1;
    //cin>>T;
    while(T--)
    {
    
    
        int n,m;
        cin>>n>>m;
        ll s=0;
        for(int i=1;i<=n;i++) 
        {
    
    
            int a;
            cin>>a;
            s+=a;
        }
        cout<<C(m+n,s+n)<<'\n';
    }
    return 0;
}

Dig a hole first

Guess you like

Origin blog.csdn.net/Fighting_Peter/article/details/112176392