func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MX = 256;   vector<vector<vector<vector<vector<int> > > > > dp;   char grid[MX][MX];   int R, C, mxmask, MOD = 1e9 + 7;   int ison(int x, int bit) {     if ((x & (1 << bit))) return 1;     return 0;   }   int turnoff(int x, int bit) {     if ((x & (1 << bit))) x ^= (1 << bit);     return x;   }   int turnon(int x, int bit) {     x |= (1 << bit);     return x;   }   int calc(int row, int mask, int col, int left, int tok) {     if (col == C) return calc(row + 1, mask, 0, 0, tok);     if (row == R) return 1;     int &ret = dp[row][mask][col][left][tok];     if (ret != -1) return ret;     ret = 0;     if (grid[row][col] ==  x ) {       return ret = calc(row, turnoff(mask, col), col + 1, 0, tok);     }     ret += calc(row, turnon(mask, col), col + 1, 1, tok);     ret %= MOD;     if (left || ison(mask, col)) {       ret += calc(row, mask, col + 1, left, tok);       ret %= MOD;     } else {       if (!tok) ret += calc(row, mask, col + 1, left, 1);       ret %= MOD;     }     return ret;   }   int main() {     cin >> R >> C;     for (int j = 0; j < R; j++) {       for (int i = 0; i < C; i++) {         if (R >= C)           cin >> grid[j][i];         else           cin >> grid[i][j];       }     }     if (R < C) swap(R, C);     mxmask = (1 << C);     dp.resize(R + 2);     for (auto &pp : dp) {       pp.resize(mxmask);       for (auto &qq : pp) {         qq.resize(C + 2);         for (auto &ll : qq) {           ll.resize(2);           for (auto &nn : ll) {             nn.resize(2);             nn[0] = nn[1] = -1;           }         }       }     }     cout << calc(0, 0, 0, 0, 0);   }   