观察到 .
所以 ,设答案为 分类讨论。
.
.
.
当 .
当 .
当 .
明显是一道状态压缩 dp 题目。
所以可以直接完成。
因为只能一个一个放。
#include <cstring>
#include <iostream>
using namespace std;
const int N = 8, M = 1 << N;
typedef long long ll;
int n, m, k, T;
ll dp[N][M];
bool st[M];
int main() {
cin >> T;
while (T--) {
cin >> n >> m >> k;
if (n > m)swap(n, m);
if (k == 5) {
cout << 1 << endl;
} else if (k == 4) {
cout << 1 << endl;
} else if (k == 3) {
if (n == 2 && m == 3) {
cout << 3 << endl;
} else if (n == 3 && m == 3) {
cout << 10 << endl;
} else {
cout << 1 << endl;
}
} else if (k == 1) {
cout << 1 << endl;
} else {
if (n == 1) {
cout << 1 << endl;
continue;
}
if (k != 2)continue;
for (int i = 0; i < 1 << n; i++) {
int cnt = 0;
st[i] = 1;
for (int j = 0; j < n; j++) {
if (i >> j & 1) {
if (cnt & 1) {
st[i] = 0;
}
cnt = 0;
} else {
cnt++;
}
}
if (cnt & 1) {
st[i] = 0;
}
}
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
for (int i = 1; i <= m; i++) {
for (int j = 0; j < 1 << n; j++) {
for (int k = 0; k < 1 << n; k++) {
if ((j & k) == 0 && st[j | k]) {
dp[i][j] += dp[i - 1][k];
}
}
}
}
cout << dp[m][0] << endl;
}
}
return 0;
}
