题目描述
方法:
状压DP
#include <cstdio> #define bc(x) (__builtin_popcount(x)) const int mod = 998244353; const int maxn = 12; int f[maxn][1 << maxn][maxn * maxn]; int main() { int n, m, p; scanf("%d%d%d", &n, &m, &p); for (int i = 0; i < 1 << m; ++i) f[1][i][bc(i)] = 1; for (int i = 2; i <= n; ++i) { for (int j = 0; j < 1 << m; ++j) { for (int k = 0; k < 1 << m; ++k) { if ((j << 1) & k) continue; if (j & (k << 1)) continue; for (int l = p; l >= bc(k); --l) f[i][k][l] = (f[i][k][l] + f[i - 1][j][l - bc(k)]) % mod; } } } static int ans; for (int i = 0; i < 1 << m; ++i) ans = (ans + f[n][i][p]) % mod; printf("%d ", ans); return 0; }