#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 16;
int n, m;
bool st[(1 << N)];
long long f[N][(1 << N)];
int main() {
// 为了节省点时间
// 预处理放到外边就出错了
for (int i = 0; (i < (1 << N)); ++i) {
st[i] = true;
/* cnt 连续 0 的个数 */
int cnt = 0;
for (int j = 0; j < N; ++j) {
if (((i >> j) & 1) == 1) {
if ((cnt & 1) == 1) {
st[i] = false;
}
cnt = 0;
}
else
cnt++;
}
if ((cnt & 1) == 1)
st[i] = false;
}
// 为什么???
while (cin >> n >> m, n || m) {
memset(f, 0, sizeof f);
memset(st, false, sizeof st);
// 预处理
// for (int i = 0; (i < (1 << n)); ++i) {
// st[i] = true;
/* cnt 连续 0 的个数 */
// int cnt = 0;
// for (int j = 0; j < n; ++j) {
// if (((i >> j) & 1) == 1) {
// if ((cnt & 1) == 1) {
// st[i] = false;
// }
// cnt = 0;
// }
// else
// cnt++;
// }
// if ((cnt & 1) == 1)
// st[i] = false;
// }
/* dp 开始 */
f[0][0] = 1;
for (int i = 1; i <= m; ++i)
for (int j = 0; j <= ((1 << n) - 1); ++j)
for (int k = 0; k <= ((1 << n) - 1); ++k)
if (((j & k) == 0) && (st[(j | k)])) {
f[i][j] += f[i - 1][k];
}
cout << f[m][0] << endl;
}
return 0;
}
找工作确实java好写
但是写算法题,c++还不错
好巧我刚好是想反着转Java但是不知道怎么转hhh