1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| #include <bits/stdc++.h> using namespace std; typedef long long ll;
const int MAXN = 100005, MAXM = 20005; const ll MOD = 998244353, G = 3;
inline ll qpow(ll a, ll k) { ll ret = 1; while (k) { if (k & 1) ret = ret * a % MOD; a = a * a % MOD; k >>= 1; } return ret; }
namespace FFT { int n, r[MAXN << 1]; void NTT(ll *a, int op) { int k = 0; for (; (1 << k) < n; ++k); for (int i = 0; i < n; ++i) { r[i] = r[i >> 1] >> 1 | (i & 1) << (k - 1); if (i < r[i]) swap(a[i], a[r[i]]); } for (int l = 2; l <= n; l <<= 1) { int m = l >> 1; ll w = qpow(G, (MOD - 1) / l); if (op == -1) w = qpow(w, MOD - 2); for (int i = 0; i < n; i += l) { ll wk = 1; for (int j = 0; j < m; ++j, wk = wk * w % MOD) { ll p = a[i + j], q = wk * a[i + j + m] % MOD; a[i + j] = (p + q) % MOD; a[i + j + m] = (p - q + MOD) % MOD; } } } } void DFT(ll *a) { NTT(a, 1); } void IDFT(ll *a) { NTT(a, -1); ll inv = qpow(n, MOD - 2); for (int i = 0; i < n; ++i) a[i] = a[i] * inv % MOD; } }
int m, n, k; int a[MAXM]; vector<ll> b[MAXM << 1]; priority_queue<pair<int, int> > q; ll x[MAXN << 1], y[MAXN << 1], ans; ll fac[MAXN], inv[MAXN], facinv[MAXN];
inline ll C(int n, int k) { return fac[n] * facinv[k] % MOD * facinv[n - k] % MOD; }
int main() { scanf("%d%d%d", &m, &n, &k); fac[0] = facinv[0] = 1; fac[1] = inv[1] = facinv[1] = 1; for (int i = 2; i <= n; ++i) { fac[i] = fac[i - 1] * i % MOD; inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD; facinv[i] = facinv[i - 1] * inv[i] % MOD; } for (int i = 1; i <= m; ++i) { scanf("%d", &a[i]); for (int j = 0; j < a[i]; ++j) b[i].push_back(C(a[i], j) * fac[a[i] - 1] % MOD * facinv[a[i] - j - 1] % MOD); q.push(make_pair(-b[i].size(), i)); } int cnt = m; while (q.size() > 1) { int id1 = q.top().second, sz1 = -q.top().first; q.pop(); int id2 = q.top().second, sz2 = -q.top().first; q.pop(); FFT::n = 1; while (FFT::n <= sz1 + sz2) FFT::n <<= 1; for (int i = 0; i <= FFT::n; ++i) x[i] = y[i] = 0; for (int i = 0; i < sz1; ++i) x[i] = b[id1][i]; for (int i = 0; i < sz2; ++i) y[i] = b[id2][i]; FFT::DFT(x), FFT::DFT(y); for (int i = 0; i <= FFT::n; ++i) x[i] = x[i] * y[i] % MOD; FFT::IDFT(x); cnt++; for (int i = 0; i <= sz1 + sz2 - 2; ++i) b[cnt].push_back(x[i]); q.push(make_pair(-b[cnt].size(), cnt)); } int id = q.top().second, sz = -q.top().first; for (int i = k; i < sz; ++i) { ll tmp = C(i, k) * fac[n - i] % MOD * b[id][i] % MOD; if ((i - k) & 1) ans = (ans - tmp + MOD) % MOD; else ans = (ans + tmp) % MOD; } for (int i = 1; i <= m; ++i) ans = ans * qpow(fac[a[i]], MOD - 2) % MOD; printf("%lld", ans); return 0; }
|