void solve() {
    int n, k;
    cin >> n >> k;

    vector f(k + 1, vector(1 << n, vector(n + 1, 0ll)));
    f[0][0][0] = 1;

    for (int i = 1; i <= n; i++) {
        for (int c = 0; c <= k; c++) {
            for (int x = 0; x < 1 << n; x++) {
                int cx = __builtin_popcount(x);
                if (c - cx < 0) continue;
                for (int y = 0; y < 1 << n; y++) {
                    if ((x & x >> 1) || ((y | y >> 1 | y << 1) & x)) continue;
                    f[c][x][i] += f[c - cx][y][i - 1];
                }
            }
        }
    }
    ll res = 0;
    for (int x = 0; x < 1 << n; x++) res += f[k][x][n];
    cout << res << '\n';
}

0 条评论

目前还没有评论...

信息

ID
453
时间
ms
内存
MiB
难度
7
标签
递交数
19
已通过
8
上传者