题目
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;const int mod = 1e8;
const int M = 1 << 12;
LL f[13][M];
int g[13];
vector<int> state;
vector<int> p[M];
int n, m;
bool check(int x)
{return !(x & x << 1);
}
int main()
{cin >> m >> n;for(int i = 1; i <= m; i++){for(int j = 0; j < n; j++){int t;cin >> t;g[i] |= !t << j;}}for(int i = 0; i < 1 << n; i++){if(check(i)) state.push_back(i);}for(auto a : state)for(auto b : state){if((a & b) == 0) p[a].push_back(b);}f[0][0] = 1;for(int i = 1; i <= m+1; i++){for(auto a : state){f[i&1][a] = 0;if(a & g[i]) continue;for(auto b : p[a]){f[i&1][a] = (f[i&1][a] + f[(i-1)&1][b]) % mod;}}}cout << f[(m+1)&1][0];return 0;
}
注意
采用滚动数组时,一定要注意恢复,而且不仅是更新之前恢复,对于那些不更新的值也要恢复,因为不更新不代表继承上一次的值,而是采用默认值,因此必须恢复,下面的这个代码就闹了这个笑话
f[0][0] = 1;for(int i = 1; i <= m+1; i++){for(auto a : state){f[i&1][a] = 0;if(a & g[i]) continue;//f[i&1][a] = 0;for(auto b : p[a]){f[i&1][a] = (f[i&1][a] + f[(i-1)&1][b]) % mod;}}}