1 条题解
-
0
参考答案:
#include<iostream> #include<vector> using namespace std; const int N = 14, M = 1 << 14, mod = 1e8; int n, m; int w[N]; int f[N][M]; vector<int> state, v[M]; bool check(int x) { for (int i = 0; i < m - 1; ++i) if (((x >> i) & 1) && (x >> (i + 1)) & 1) return false; return true; } int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 0; j < m; ++j) { int t; cin >> t; w[i] += !t * (1 << j); } } for (int i = 0; i < 1 << m; ++i) if (check(i)) state.push_back(i); for (int i = 0; i < state.size(); ++i) { for (int j = 0; j < state.size(); ++j) { int a = state[i], b = state[j]; if (!(a & b)) v[i].push_back(j); } } f[0][0] = 1; for (int i = 1; i <= n + 1; ++i) { for (int j = 0; j < state.size(); ++j) { if (!(state[j] & w[i])) { for (auto t : v[j]) { f[i][j] = (f[i][j] + f[i - 1][t]) % mod; } } } } cout << f[n + 1][0] << endl; return 0; }
- 1
信息
- ID
- 5358
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 3
- 已通过
- 1
- 上传者