Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <map>
- using namespace std;
- const int MOD = 1000000007;
- void add(int & a, int b) {
- a += b;
- if (a >= MOD) a -= MOD;
- }
- int a[123][123];
- int main() {
- map<long long, int> ways;
- int n, m;
- scanf("%d%d", &n, &m);
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- int c = getchar();
- while (c <= 32) c = getchar();
- a[i][j] = c;
- }
- }
- ways[0] = 1;
- for (int col = 0; col < m; col++) {
- for (int row = 0; row < n; row++) {
- map<long long, int> nways;
- for (map<long long, int> :: iterator it = ways.begin(); it != ways.end(); ++it) {
- long long state = it->first;
- for (int c = 1; c <= 3; c++) {
- if (a[row][col] != '.' && a[row][col] != "BGW"[c - 1]) continue;
- if (row > 0 && ((state >> (2 * (row - 1))) & 3) == c) continue;
- int cc = ((state >> (2 * row)) & 3);
- if (cc == c) continue;
- long long nState = state ^ ((cc ^ c) << (2 * row));
- add(nways[nState], it->second);
- }
- }
- ways.swap(nways);
- }
- }
- int ans = 0;
- for (map<long long, int> :: iterator it = ways.begin(); it != ways.end(); ++it) {
- add(ans, it->second);
- }
- printf("%d\n", ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment