位运算的状态压缩太操蛋了,很容易出错。。。又是数组没开够导致诡异现象(明明某个值是1,莫名其妙就变成0了),害我debug一整天!fuck
代码:
#include <iostream>
#include <cstring> using namespace std; #define MAX_N 1024
#define MAX_M 8
#define MAX_S 4096
#define MOD 1000000007 int f[MAX_N][MAX_M][MAX_S];
int N, M; bool freep(int s, int o) {
return !(s & ( << o));
} int mark(int s, int o) {
return s |= ( << o);
} int mark(int s, int o1, int o2) {
return mark(s, o1) | mark(s, o2);
} int main() {
cin >> N >> M;
memset(f, , sizeof(f)); for (int i = ; i <= N; i++) {
for (int s = ; s < ( << ( * M + )); s++)
f[i][M + ][s] = ;
}
for (int j = ; j <= M; j++) {
for (int s = ; s < ( << ( * M + )); s++)
f[N + ][j][s] = ;
} for (int i = N; i >= ; i--) {
for (int j = M; j >= ; j--) {
for (int k = ( << ( * M)) - ; k >= ; k--) {
int s = k << ;
// pass
if (!freep(s, j)) {
if (j < M)
f[i][j][s] = f[i][j + ][s];
if (j == M)
f[i][j][s] = f[i + ][][(s >> M) >> << ];
}
if (freep(s, j)) {
// impossible
if ((j == M || !freep(s, j + )) && (i == N || !freep(s, j + M)))
f[i][j][s] = ;
// right
if (j < M && freep(s, j + ) && (i == N || !freep(s, j + M)))
f[i][j][s] += f[i][j][mark(s, j, j + )];
// down
if (i < N && freep(s, j + M) && (j == M || !freep(s, j + )))
f[i][j][s] += f[i][j][mark(s, j, j + M)];
// right & down
if (j < M && freep(s, j + ) && i < N && freep(s, j + M))
f[i][j][s] = (f[i][j][mark(s, j, j + )] + f[i][j][mark(s, j, j + M)]) % MOD;
}
}
}
} cout << f[][][] << endl; return ;
}