• 欢迎光临~

# 唱、跳、rap和篮球

## 思路

(-3i) 就相当于你把原本长度为四的 (abcd) 压缩为 (e)，每个少了三个字符，然后你就随便选 (i) 个位置放 (e)

（其中 (dfrac{1}{a!}) 的最高项位置就是它能放的 (a) 个数，(bcd) 同理）

## 代码

``````#include<cstdio>
#include<iostream>
#include<algorithm>
#define mo 998244353

using namespace std;

int n, a, b, c, d, ans, di, m;
int jc[20001], inv[20001], G, Gv;
int limit, l_size, an[20001];
int A[20001], B[20001], C[20001], D[20001];

int jia(int x, int y) {
return (x + y >= mo) ? x + y - mo : x + y;
}

int jian(int x, int y) {
return (x < y) ? (x - y + mo) : (x - y);
}

int cheng(int x, int y) {
return 1ll * x * y % mo;
}

int CC(int n, int m) {
if (m < 0 || m > n) return 0;
return cheng(jc[n], cheng(inv[m], inv[n - m]));
}

int ksm(int x, int y) {
int re = 1;
while (y) {
if (y & 1) re = cheng(re, x);
x = cheng(x, x); y >>= 1;
}
return re;
}

void NTT(int *f, int op) {
for (int i = 0; i < limit; i++)
if (i < an[i]) swap(f[i], f[an[i]]);
for (int mid = 1; mid < limit; mid <<= 1) {
int Wn = ksm((op == 1) ? G : Gv, (mo - 1) / (mid << 1));
for (int R = (mid << 1), j = 0; j < limit; j += R) {
int w = 1;
for (int k = 0; k < mid; k++, w = cheng(w, Wn)) {
int x = f[j + k], y = cheng(w, f[j + mid + k]);
f[j + k] = jia(x, y); f[j + mid + k] = jian(x, y);
}
}
}
if (op == -1) {
int invl = ksm(limit, mo - 2);
for (int i = 0; i < limit; i++) f[i] = cheng(f[i], invl);
}
}

int P(int n, int a, int b, int c, int d) {
if (n < 0 || a + b + c + d < n) return 0;
limit = 1; l_size = 0;
while (limit <= (a + b + c + d) * 2) {
limit <<= 1; l_size++;
}
for (int i = 0; i < limit; i++)
an[i] = (an[i >> 1] >> 1) | ((i & 1) << (l_size - 1));

for (int i = 0; i < limit; i++) {
A[i] = (i <= a) ? inv[i] : 0;
B[i] = (i <= b) ? inv[i] : 0;
C[i] = (i <= c) ? inv[i] : 0;
D[i] = (i <= d) ? inv[i] : 0;
}
NTT(A, 1); NTT(B, 1); NTT(C, 1); NTT(D, 1);
for (int i = 0; i < limit; i++)
A[i] = cheng(cheng(A[i], B[i]), cheng(C[i], D[i]));
NTT(A, -1);

return cheng(jc[n], A[n]);
}

int main() {
G = 3; Gv = ksm(G, mo - 2);
jc[0] = 1; for (int i = 1; i <= 20000; i++) jc[i] = cheng(jc[i - 1], i);
inv[0] = inv[1] = 1; for (int i = 2; i <= 20000; i++) inv[i] = cheng(inv[mo % i], mo - mo / i);
for (int i = 1; i <= 20000; i++) inv[i] = cheng(inv[i - 1], inv[i]);

scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
m = min(min(a, b), min(c, d));

ans = 0; di = 1;
for (int i = 0; i <= m; i++) {
ans = jia(ans, cheng(cheng(di, CC(n - 3 * i, i)), P(n - 4 * i, a - i, b - i, c - i, d - i)));
di = mo - di;
}
printf("%d", ans);

return 0;
}
``````