当前位置:网站首页>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);
}
边栏推荐
- [OBS] win capture requires winrt
- B. Value sequence thinking
- paddlepaddle 29 无模型定义代码下动态修改网络结构(relu变prelu,conv2d变conv3d,2d语义分割模型改为3d语义分割模型)
- 探索干货篇!Apifox 建设思路
- Hands on deep learning (IV) -- convolutional neural network CNN
- C language queue
- [UTCTF2020]file header
- pytest+allure+jenkins環境--填坑完畢
- The charm of SQL optimization! From 30248s to 0.001s
- Button wizard script learning - about tmall grabbing red envelopes
猜你喜欢

IO stream file
![[Stanford Jiwang cs144 project] lab3: tcpsender](/img/82/5f99296764937e7d119b8ab22828fd.png)
[Stanford Jiwang cs144 project] lab3: tcpsender

Sign up now | oar hacker marathon phase III, waiting for your challenge
![[quick start of Digital IC Verification] 15. Basic syntax of SystemVerilog learning 2 (operators, type conversion, loops, task/function... Including practical exercises)](/img/e1/9a047ef13299b94b5314ee6865ba26.png)
[quick start of Digital IC Verification] 15. Basic syntax of SystemVerilog learning 2 (operators, type conversion, loops, task/function... Including practical exercises)

The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)

Content of string

开源生态|打造活力开源社区,共建开源新生态!

misc ez_ usb

3D reconstruction - stereo correction

LeetCode 90:子集 II
随机推荐
nacos
Leetcode 43 String multiplication (2022.02.12)
Figure out the working principle of gpt3
Pytest+allure+jenkins installation problem: pytest: error: unrecognized arguments: --alluredir
mysql多列索引(组合索引)特点和使用场景
Padavan manually installs PHP
Explore dry goods! Apifox construction ideas
Linux server development, MySQL transaction principle analysis
Jenkins remote build project timeout problem
Info | webrtc M97 update
解决问题:Unable to connect to Redis
C语言队列
Live online system source code, using valueanimator to achieve view zoom in and out animation effect
芯片 設計資料下載
Visualization Document Feb 12 16:42
The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)
Rust Versus Go(哪种是我的首选语言?)
Content of string
Paddlepaddle 29 dynamically modify the network structure without model definition code (relu changes to prelu, conv2d changes to conv3d, 2D semantic segmentation model changes to 3D semantic segmentat
IO stream file