无限手套
每 种 宝 石 的 生 成 函 数 为 ∑ n ≥ 0 x n ( a i n 2 + b i n + 1 ) 对 其 进 行 化 简 ∑ n ≥ 0 x n + ∑ n ≥ 0 b i n x n + ∑ n ≥ 0 a i n 2 x n 1 1 − x + b i x ( 1 − x ) 2 + a i x ( 1 + x ) ( 1 − x ) 3 最 后 答 案 ∏ i = 1 m ( ( a i − b i + 1 ) x 2 + ( a i + b i − 2 ) x + 1 ) ( 1 − x ) 3 m 每种宝石的生成函数为\sum_{n \geq 0} x ^ n(a_i n ^ 2 + b_i n + 1)\\ 对其进行化简\sum_{n \geq 0} x ^ n + \sum_{n \geq 0} b_i n x ^ n + \sum_{n\geq 0} a_i n ^ 2 x ^ n\\ \frac{1}{1 - x} + \frac{b_i x}{(1 - x) ^ 2} + \frac{a_ i x (1 + x)}{(1 - x) ^ 3}\\ 最后答案\frac{\prod\limits_{i = 1} ^{m} \left((a_i - b_i + 1) x ^ 2 + (a_i + b_i - 2) x + 1 \right)}{(1 - x) ^{3m}}\\ 每种宝石的生成函数为n≥0∑xn(ain2+bin+1)对其进行化简n≥0∑xn+n≥0∑binxn+n≥0∑ain2xn1−x1+(1−x)2bix+(1−x)3aix(1+x)最后答案(1−x)3mi=1∏m((ai−bi+1)x2+(ai+bi−2)x+1)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, mod = 998244353;
int fac[N], inv[N];
int quick_pow(int a, int n) {
int ans = 1;
while (n) {
if (n & 1) {
ans = 1ll * ans * a % mod;
}
a = 1ll * a * a % mod;
n >>= 1;
}
return ans;
}
int C(int n, int m) {
if(n < 0 || m < 0 || m > n) return 0;
if(m == 0 || m == n) return 1;
return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
void init() {
fac[0] = 1;
for(int i = 1; i < N; i++)
fac[i] = 1ll * fac[i - 1] * i % mod;
inv[N - 1] = quick_pow(fac[N - 1], mod - 2);
for(int i = N - 2; i >= 0; i--)
inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
}
int A[N], n, m;
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
init();
scanf("%d", &m);
A[0] = 1;
for (int i = 1, a, b; i <= m; i++) {
scanf("%d %d", &a, &b);
int x = (a - b + 1 + mod) % mod, y = (a + b - 2) % mod, z = 1;
for (int i = 2 * m; i >= 2; i--) {
A[i] = (1ll * A[i - 2] * x % mod + 1ll * A[i - 1] * y % mod + 1ll * A[i] * z % mod) % mod;
}
A[1] = (1ll * A[0] * y % mod + 1ll * A[1] * z % mod) % mod;
A[0] = 1ll * A[0] * z % mod;
}
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
int ans = 0;
for (int i = 0; i <= n; ++i) {
ans = (ans + 1ll * C(3 * m + i - 1, i) * A[n - i] % mod) % mod;
}
printf("%d\n", ans);
}
return 0;
}