当前位置:网站首页>Niu Mei's mathematical problem --- combinatorial number
Niu Mei's mathematical problem --- combinatorial number
2022-07-07 08:01:00 【Wawa source】
#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);
}
边栏推荐
- Live online system source code, using valueanimator to achieve view zoom in and out animation effect
- @component(““)
- 图解GPT3的工作原理
- 自定义类加载器加载网络Class
- 2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
- Why should we understand the trend of spot gold?
- CTF daily question day43 rsa5
- Technology cloud report: from robot to Cobot, human-computer integration is creating an era
- Content of string
- JS quick start (I)
猜你喜欢
Explore Cassandra's decentralized distributed architecture
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
2022焊工(初级)判断题及在线模拟考试
Linux server development, redis protocol and asynchronous mode
nacos
Main window in QT learning 27 application
Operation suggestions for today's spot Silver
Ansible
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
探索Cassandra的去中心化分布式架构
随机推荐
Redis technology leak detection and filling (II) - expired deletion strategy
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
Numbers that appear only once
Linux server development, MySQL transaction principle analysis
C语言二叉树与建堆
有 Docker 谁还在自己本地安装 Mysql ?
CentOS7下安装PostgreSQL11数据库
Linux server development, MySQL stored procedures, functions and triggers
Who has docker to install MySQL locally?
Binary tree and heap building in C language
JSON data flattening pd json_ normalize
SQL优化的魅力!从 30248s 到 0.001s
Wechat applet data binding multiple data
A bit of knowledge - about Apple Certified MFI
C语言航班订票系统
2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
Chip information website Yite Chuangxin
[2022 actf] Web Topic recurrence
PHP exports millions of data
[UVM practice] Chapter 2: a simple UVM verification platform (2) only driver verification platform