版本比较
fjdrhsthtrht
正文
增加 27 行删除 21 行
1234556789101112131415161718192021222324678910111213141516171819202122232425262728293031263233```cpp#include <bits/stdc++.h>#define int long longusing namespace std;
const int kN = 105, kM = 1 << 6, mod = 1e9 + 7;int n, m, k;int dp[kN][25][kM][kM];int main() { cin >> n >> m >> k; dp[0][0][0][0] = 1; for (int i = 1; i <= m; i++) for (int j = 0; j <= k; j++) for (int x = 0; x < (1 << n); x++) if (j >= __builtin_popcount(x)) for (int y = 0; y < (1 << n); y++) if ((x & (y >> 2)) == 0 && (x & (y << 2)) == 0) for (int z = 0; z < (1 << n); z++) if ((y & (z >> 2)) == 0 && (y & (z << 2)) == 0 && (x & (z >> 1)) == 0 && (x & (z << 1)) == 0) dp[i][j][x][y] = (dp[i][j][x][y] + dp[i - 1][j - __builtin_popcount(x)][y][z]) % mod; int ans = 0; for (int x = 0; x < (1 << n); x++) for (int y = 0; y < (1 << n); y++) ans = (ans + dp[m][k][x][y]) % mod; cout << ans;const int kN = 10, kM = 1 << 9, kK = 85;int n, k;int dp[kN][kK][kM], val[kM];signed main() { cin >> n >> k; for (int i = 0; i < (1 << n); i++) val[i] = __builtin_popcount(i); dp[0][0][0] = 1; for (int i = 1; i <= n; i++) for (int x = 0; x < (1 << n); x++) for (int y = 0; y < (1 << n); y++) { if ((x & (x << 1)) || (x & (x >> 1))) continue; for (int j = val[x]; j <= k; j++) { if ((y & (x >> 1) || (y & (x << 1))) || (y & x) != 0) continue; dp[i][j][x] += dp[i - 1][j - __builtin_popcount(x)][y]; } } int ans = 0; for (int i = 0; i < (1 << n); i++) ans += dp[n][k][i]; if (k == 1) cout << n * n; else cout << ans; return 0;} }```