当前位置:网站首页>Niu Mei's mathematical problem --- combinatorial number

Niu Mei's mathematical problem --- combinatorial number

2022-07-07 08:01:00 Wawa source

 Insert picture description here
 Insert picture description here

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int>PII;
#define int long long
const int N =10000010,mod=998244353;
int n,k;
int fact[N],infact[N],p2[N];
int x;
int qmi(int a,int b)
{
    
    int res=1;
    while(b)
    {
    
        if(b&1)res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res%mod;
}
int C(int a,int b)
{
    
    if(a<b)return 0;
    return fact[a]*infact[b]%mod*infact[a-b]%mod;
}
signed main()
{
    
    scanf("%lld %lld",&n,&k);
    int cnt1=0,cnt2=0;
    for(int i=1;i<=n;i++)
    {
    
        scanf("%lld",&x);
        if(x==1)cnt1++;
        else if(x==2)cnt2++;
    }
    
    // Preprocessing 
    p2[0]=fact[0]=infact[0]=1;
    for(int i=1;i<=n;i++)
    {
    
        fact[i]=fact[i-1]*i%mod;
        p2[i]=2*p2[i-1]%mod;
    }
    infact[n]=qmi(fact[n],mod-2);
    for(int i=n-1;i>=1;i--)infact[i]=infact[i+1]*(i+1)%mod;
    
    // Calculation 
    int res=0;
    for(int i=0;i<=k;i++)res=(res+C(cnt1,i)*C(cnt2,k-i)%mod*p2[k-i]%mod)%mod;
    printf("%lld\n",res);
}
原网站

版权声明
本文为[Wawa source]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130647365683.html