跳到正文

题解

题解:AT_ndpc2026_j 個数と総和

水星湖约 3 分钟
原文
文章信息与版本

文章信息

发布
2026年5月21日
收录
2026年7月22日
更新
2026年10月27日
篇幅
约 3 分钟
获赞
2

版本

  1. v1当前

F(x,y)=1∏i=1n(1−xyai)F(x,y)=\frac{1}{\prod_{i=1}^n (1-xy^{a_i})},答案为 [xsyt]F(x,y)[x^sy^t]F(x,y)。

令 P(x,y)=∏i=1n(1+xyai)P(x,y)=\prod_{i=1}^n (1+xy^{a_i}),F(x,y)=P(x,y)∏i=1n(1−x2y2ai)=P(x,y)F(x2,y2)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)。

令 Q0(x,y)=1Q_0(x,y)=1,F(x,y)=Q0(x,y)P(x,y)F(x2,y2)F(x,y)=Q_0(x,y)P(x,y)F(x^2,y^2)。

令 G0(x,y)=Q0(x,y)P(x,y)G_0(x,y)=Q_0(x,y)P(x,y),[xsyt]F(x,y)=[xsyt]G0(x,y)F(x2,y2)=[x⌊s/2⌋y⌊t/2⌋]Q1(x,y)F(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)。其中 Q1(x,y)Q_1(x,y) 为将 G0(x,y)G_0(x,y) 中系数奇偶性满足条件的项的次数除以 22 得到的多项式。这样就可以递归下去。

答案即为 Q60(x,y)F(x,y)Q_{60}(x,y)F(x,y) 的常数项,其中 F(x,y)F(x,y) 常数项显然为 11。

C++
#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;
}
原文