当前位置:网站首页>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);
}
边栏推荐
- 【数字IC验证快速入门】17、SystemVerilog学习之基本语法4(随机化Randomization)
- Button wizard collection learning - mineral medicine collection and running map
- [P2P] local packet capturing
- [quick start of Digital IC Verification] 15. Basic syntax of SystemVerilog learning 2 (operators, type conversion, loops, task/function... Including practical exercises)
- Why should we understand the trend of spot gold?
- 大视频文件的缓冲播放原理以及实现
- 自定义类加载器加载网络Class
- Linux server development, MySQL stored procedures, functions and triggers
- Sign up now | oar hacker marathon phase III, waiting for your challenge
- Linux server development, MySQL cache strategy
猜你喜欢
Qt学习26 布局管理综合实例
2022 welder (elementary) judgment questions and online simulation examination
Yugu p1020 missile interception (binary search)
Numbers that appear only once
Es FAQ summary
2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
2022 Inner Mongolia latest advanced fire facility operator simulation examination question bank and answers
Custom class loader loads network class
Force buckle 144 Preorder traversal of binary tree
2022 tea master (intermediate) examination questions and mock examination
随机推荐
[Stanford Jiwang cs144 project] lab4: tcpconnection
Li Kou interview question 04.01 Path between nodes
Custom class loader loads network class
Thinkcmf6.0安装教程
Zhilian + AV, AITO asked M7 to do more than ideal one
C language queue
C语言队列
Jenkins remote build project timeout problem
nacos
Chip design data download
B. Value sequence thinking
Pytest + allure + Jenkins Environment - - achèvement du remplissage de la fosse
芯片 设计资料下载
Hands on deep learning (IV) -- convolutional neural network CNN
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
Linux server development, redis protocol and asynchronous mode
[2022 ciscn] replay of preliminary web topics
芯片 設計資料下載
C语言通信行程卡后台系统
JS quick start (I)