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
| #include <cstdio> using namespace std; template <class Type> void read (Type &x) { char c; bool flag = false; while ((c = getchar()) < '0' || c > '9') c == '-' && (flag = true); x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0'; flag && (x = ~x + 1); } template <class Type, class ...rest> void read (Type &x, rest &...y) { read(x), read(y...); } template <class Type> void write (Type x) { x < 0 && (putchar('-'), x = ~x + 1); x > 9 && (write(x / 10), 0); putchar('0' + x % 10); } typedef long long LL; const int N = 40, M = 110, mod = 998244353; int n, m, h, cnt[N], C[N][N], p[M][N], f[M][N][N][N >> 1]; void add (int &x, LL k) { x = (x + k) % mod; } void add (int &x, int k) { x += k - mod, x += x >> 31 & mod; } void init () { for (int i = 0; i <= n; ++i) C[i][0] = 1; for (int i = 1; i < N; ++i) for (int j = 1; j <= i; ++j) add(C[i][j] = C[i - 1][j], C[i - 1][j - 1]); for (int i = 1; i < N; ++i) cnt[i] = cnt[i >> 1] + (i & 1); for (int i = 0, a; i <= m; ++i) { read(a); p[i][0] = 1; for (int j = 1; j <= n; ++j) p[i][j] = (LL)p[i][j - 1] * a % mod; } } int main () { read(n, m, h); init(); f[0][0][0][0] = 1; for (int i = 0; i <= m; ++i) for (int j = 0; j <= n; ++j) for (int k = 0; k <= h; ++k) for (int s = 0; s <= n >> 1; ++s) for (int t = 0; j + t <= n; ++t) add(f[i + 1][j + t][k + (t + s & 1)][t + s >> 1], (LL)p[i][t] * C[n - j][t] % mod * f[i][j][k][s]); int res = 0; for (int k = 0; k <= h; ++k) for (int s = 0; s <= n >> 1; ++s) if (k + cnt[s] <= h) add(res, f[m + 1][n][k][s]); write(res); return 0; }
|