include iostream include iomanip include cstdio include string include

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef ld DOUBLE;
#define PATH "D:\\QtProjects\\olymp\\"
template <class T> void mx(T& a, const T& b) { if (a < b) a = b; }
template <class T> void mn(T& a, const T& b) { if (a > b) a = b; }
const int N = 300000;
int cnt[N + 1];
const int N = 14;
const int M = 50;
string A[N];
const ll P = 1000000007;
vector<int> masks[25000];
int maskscnt;
inline void g1(vector<int>& m, int n, int cursz){
if (cursz == n){
masks[maskscnt++] = m;
return;
}
if (cursz == 0)
{
m[cursz] = 0;
g1(m, n, cursz + 1);
m[cursz] = 1;
g1(m, n, cursz + 1);
m[cursz] = 2;
g1(m, n, cursz + 1);
}
else
{
if (m[cursz - 1] == 0){
m[cursz] = 1;
g1(m, n, cursz + 1);
m[cursz] = 2;
g1(m, n, cursz + 1);
}
if (m[cursz - 1] == 1){
m[cursz] = 0;
g1(m, n, cursz + 1);
m[cursz] = 2;
g1(m, n, cursz + 1);
}
if (m[cursz - 1] == 2){
m[cursz] = 1;
g1(m, n, cursz + 1);
m[cursz] = 0;
g1(m, n, cursz + 1);
}
}
}
vector<int> g[25000];
inline bool chkmasks(const vector<int>& a, const vector<int>& b){
for (int i = 0; i < (int)a.size(); ++i)
if (a[i] == b[i])
return false;
return true;
}
const char C[] = {'W', 'B', 'G'};
inline bool checkmask(const vector<int> & mask, const int line){
for (int i = 0; i < (int)mask.size(); ++i)
if (A[i][line] != '.' && A[i][line] != C[mask[i]])
return false;
return true;
}
inline void generatemasks(const int n){
vector<int> t(n);
g1(t, n, 0);
int nn = maskscnt;
for (int i = 0; i < nn; ++i)
for (int j = 0; j < i; ++j)
if (chkmasks(masks[i], masks[j])){
g[i].push_back(j);
g[j].push_back(i);
}
}
ll dp[50][25000];
int main(){
//freopen(PATH"input.txt", "r", stdin);
ios_base::sync_with_stdio(false);
maskscnt = 0;
int n, m;
cin >> n >> m;
generatemasks(n);
getline(cin, A[0]);
for (int i = 0; i < n; ++i)
getline(cin, A[i]);
int cnt = maskscnt;
for (int i = 0; i < cnt; ++i)
dp[0][i] = checkmask(masks[i], 0);
for (int line = 1; line < m; ++line){
for (int i = 0; i < cnt; ++i) if (checkmask(masks[i], line)){
for (int j = 0; j < g[i].size(); ++j)
dp[line][i] += dp[line - 1][g[i][j]];
dp[line][i] %= P;
}
}
ll ans = 0;
for (int i = 0; i < cnt; ++i)
ans += dp[m - 1][i];
ans %= P;
cout << ans << endl;
return 0;
}