#include #include #include using namespace std; #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define MAXW 110 #define MAXH 110 const long long MOD = 1000000007; int H, W; string str[MAXH]; bool canZero[MAXW], canIchi[MAXW]; // can put 0/1 in (0, i) ? bool canZeroIchi[MAXH], canIchiZero[MAXH]; int main() { while (cin >> H >> W) { for (int i = 0; i < H; ++i) cin >> str[i]; // the first row is neither 010101010101... nor 10101010... long long res1 = 1; for (int i = 0; i < MAXW; ++i) canZero[i] = canIchi[i] = true; for (int i = 0; i < W; ++i) { for (int j = 0; j < H; ++j) { if (str[j][i] == '0') { if (j & 1) canZero[i] = false; else canIchi[i] = false; } else if (str[j][i] == '1') { if (j & 1) canIchi[i] = false; else canZero[i] = false; } } int con = 0; if (canZero[i]) ++con; if (canIchi[i]) ++con; (res1 *= con) %= MOD; } bool canStartZero = true, canStartIchi = true; for (int i = 0; i < W; ++i) { if (i & 1) { if (!canZero[i]) canStartIchi = false; if (!canIchi[i]) canStartZero = false; } else { if (!canZero[i]) canStartZero = false; if (!canIchi[i]) canStartIchi = false; } } if (canStartZero) --res1; if (canStartIchi) --res1; // the first row is 010101010101... or 10101010... long long res2 = 1; for (int i = 0; i < MAXH; ++i) canZeroIchi[i] = canIchiZero[i] = true; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (str[i][j] == '0') { if (j & 1) canZeroIchi[i] = false; else canIchiZero[i] = false; } else if (str[i][j] == '1') { if (j & 1) canIchiZero[i] = false; else canZeroIchi[i] = false; } } int con = 0; if (canZeroIchi[i]) ++con; if (canIchiZero[i]) ++con; (res2 *= con) %= MOD; } long long res = (res1 + res2) % MOD; cout << res << endl; } }