题解:AT_ndpc2026_j 個数と総和
水星湖
·
·
题解
令 $P(x,y)=\prod_{i=1}^n (1+xy^{a_i})$,$F(x,y)=\frac{P(x,y)}{\prod_{i=1}^n (1-x^2 y^{2a_i})}=P(x,y)F(x^2,y^2)$。
令 $Q_0(x,y)=1$,$F(x,y)=Q_0(x,y)P(x,y)F(x^2,y^2)$。
令 $G_0(x,y)=Q_0(x,y)P(x,y)$,$[x^sy^t]F(x,y)=[x^sy^t]G_0(x,y)F(x^2,y^2)=[x^{\lfloor s/2\rfloor}y^{\lfloor t/2\rfloor}]Q_1(x,y)F(x,y)$。其中 $Q_1(x,y)$ 为将 $G_0(x,y)$ 中系数奇偶性满足条件的项的次数除以 $2$ 得到的多项式。这样就可以递归下去。
答案即为 $Q_{60}(x,y)F(x,y)$ 的常数项,其中 $F(x,y)$ 常数项显然为 $1$。
```cpp
#include <bits/stdc++.h>
using namespace std;
namespace z {
#define int long long
const int N = 5e5 + 5, mod = 998244353;
int n, s, t;
int a[22];
int f[62][42][402];
void main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
cin >> n >> s >> t;
for(int i = 1; i <= n; i++) cin >> a[i];
f[0][0][0] = 1;
for(int i = 0; i < 60; i++) {
for(int j = 1; j <= n; j++)
for(int x = 40; x >= 1; x--)
for(int y = 400; y >= a[j]; y--)
f[i][x][y] = (f[i][x][y] + f[i][x - 1][y - a[j]]) % mod;
for(int x = s & 1; x <= 40; x += 2)
for(int y = t & 1; y <= 400; y += 2)
f[i + 1][x >> 1][y >> 1] = f[i][x][y];
s >>= 1; t >>= 1;
}
cout << f[60][0][0] << '\n';
}
#undef int
}
int main()
{
z::main();
return 0;
}
```