Thông tin
include <bits/stdc++.h>
using namespace std;
define i32 int32_t
define i64 int64_t
define all(a) a.begin(), a.end()
const i32 N = 1e6; const i32 M = 1e9 + 7; const i32 inf = 1e9 + 9; const i64 infll = 1e18 + 18;
void add(i32 &a, i32 b) {a = (a + b) % M;} bool get(i32 mask, i32 idx) {return (mask >> idx) & 1;} void print(i32 mask) { cout << " " << get(mask, 0) << endl; cout << " " << get(mask, 1) << get(mask,2) << endl; cout << get(mask, 3) << get(mask,4) << get(mask, 5) << endl; } bool check(i32 mask, i32 i, i32 j) { vector<bool> c(6); for(i32 i = 0; i < 6; i ++) c[i] = get(mask, i); if(c[5] == true) return false; c[5] = true; if((c[3] == c[4] && c[4] == c[5] && j >= 2) || (c[1] == c[2] && c[2] == c[4]) || (c[1] == c[2] && c[2] == c[5]) || (c[1] == c[4] && c[4] == c[5]) || (c[2] == c[4] && c[4] == c[5]) || (c[0] == c[2] && c[2] == c[5] && i >= 2)) return false; return true; }
void sad(i32 testID) { i32 n, m; cin >> n >> m; i32 dp[n + 1][m + 1][(1 << 6) - 1]; for(i32 i = 0; i <= n; i ++) for(i32 j = 0; j <= m; j ++) for(i32 mask = 0; mask < (1 << 6); mask ++) dp[i][j][mask] = 0; dp[0][0][0] = 1; for(i32 i = 0; i < n; i ++) for(i32 j = 0; j < m; j ++) for(i32 mask = 0; mask < (1 << 6); mask ++) { if(dp[i][j][mask] == 0) continue; print(mask); cout << i << ' ' << j << ' ' << dp[i][j][mask] << " ->\n"; vector<bool> c(6); for(i32 i = 0; i < 6; i ++) c[i] = get(mask, i); i32 nmask1 = (c[2] << 1) + (c[4] << 3) + (c[5] << 4); i32 nmask2 = (c[4] << 1) + (c[5] << 2) + c[2]; print(nmask1); print(nmask2); if(i < n - 1) if(check(nmask2, i + 1, j)) add(dp[i + 1][j][nmask1], dp[i][j][mask]); if(j < m - 1) if(check(nmask2, i, j + 1)) add(dp[i][j + 1][nmask2], dp[i][j][mask]); cout << "----\n"; if(i == n - 1 || j == m - 1) continue; if(i < 1 || j < 1) continue; if(check(nmask1, i + 1, j)) { nmask1 += 1 << 4; print(nmask1); if(i < n) add(dp[i + 1][j][nmask1], dp[i][j][mask]); } if(check(nmask2, i, j + 1)) { nmask2 += 1 << 1; print(nmask2); if(j < m) add(dp[i][j + 1][nmask2], dp[i][j][mask]); } cout << "-------\n"; }
for(i32 i = 0; i <= n; i ++) {
for(i32 j = 0; j <= m; j ++) cout << dp[i][j][0] << ' ';
cout << endl;
}
i32 res = 0;
for(i32 i = 0; i < n; i ++) for(i32 mask = 0; mask < (1 << 6); mask ++) add(res, dp[i][m - 1][mask]);
cout << res << endl;
}
signed main() { i32 t = 1; // cin >> t; for(i32 testID = 1; testID <= t; testID ++) { // cout << "Case #" << testID << endl; sad(testID); } }