# 【CTS2019】随机立方体（容斥）

## 题解

\begin{aligned} &\ \ \ \ \displaystyle {V\choose v[k]}w[k](V-v[k])!h[k]\\ &=\frac{V!}{v[k]!}w[k]h[k]\\ &=V!\frac{1}{v[k]!}w[k]h[k]\\ &=V!\frac{1}{v[k]!}w[k]\prod_{i=1}^k(v[i]-1)!\prod_{i=0}^{k-1}\frac{1}{v[i]!}\\ &=V!w[k]\prod_{i=1}^k \frac{1}{v[i]} \end{aligned}

#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 5001000
#define MOD 998244353
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
int jc[MAX],jv[MAX],inv[MAX];
int n,m,l,V,M,k,ans;
int v[MAX],w[MAX],s[MAX],invs[MAX];
int fpow(int a,int b){int s=1;while(b){if(b&1)s=1ll*s*a%MOD;a=1ll*a*a%MOD;b>>=1;}return s;}
int C(int n,int m){return 1ll*jc[n]*jv[m]%MOD*jv[n-m]%MOD;}
int main()
{
jc[0]=jv[0]=inv[0]=inv[1]=1;
for(int i=2;i<MAX;++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
for(int i=1;i<MAX;++i)jc[i]=1ll*jc[i-1]*i%MOD;
for(int i=1;i<MAX;++i)jv[i]=1ll*jv[i-1]*inv[i]%MOD;
}