当前位置:网站首页>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);
}
边栏推荐
- Wechat applet data binding multiple data
- QT learning 26 integrated example of layout management
- Numbers that appear only once
- pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
- [CV] Wu Enda machine learning course notes | Chapter 8
- Linux server development, redis protocol and asynchronous mode
- [P2P] local packet capturing
- [2022 actf] Web Topic recurrence
- 探索Cassandra的去中心化分布式架构
- Button wizard script learning - about tmall grabbing red envelopes
猜你喜欢
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
有 Docker 谁还在自己本地安装 Mysql ?
2022 welder (elementary) judgment questions and online simulation examination
[Stanford Jiwang cs144 project] lab4: tcpconnection
Explore Cassandra's decentralized distributed architecture
Most elements
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
Codeforces Global Round 19
微信小程序基本组件使用介绍
Shell 脚本的替换功能实现
随机推荐
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
Shell 脚本的替换功能实现
[VHDL parallel statement execution]
有 Docker 谁还在自己本地安装 Mysql ?
即刻报名|飞桨黑客马拉松第三期等你挑战
[UVM basics] summary of important knowledge points of "UVM practice" (continuous update...)
[unity] several ideas about circular motion of objects
Jenkins remote build project timeout problem
2022 welder (elementary) judgment questions and online simulation examination
Wechat applet data binding multiple data
开源生态|打造活力开源社区,共建开源新生态!
Figure out the working principle of gpt3
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
大视频文件的缓冲播放原理以及实现
[webrtc] M98 screen and window acquisition
C语言队列
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
Thinkcmf6.0 installation tutorial
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
Es FAQ summary