func_code_string: #include <bits/stdc++.h>   using namespace std;   string g[51];   int pre[52][52];   int dp[51][51][51][51];   bool chk(int x1, int x2, int y1, int y2) {     int r = pre[x2][y2] - pre[x1][y1 - 1] - pre[x1 - 1][y1] + pre[x1 - 1][y1 - 1];     if (r >= 1) return true;     return false;   }   int fun(int r1, int r2, int c1, int c2) {     if (chk(r1, r2, c1, c2) == false) return 0;     if (dp[r1][r2][c1][c2] != -1) return dp[r1][r2][c1][c2];     int ans = max((r2 - r1 + 1), (c2 - c1 + 1));     for (int i = r1; i < r2; i++)       ans = min(ans, fun(r1, i, c1, c2) + fun(i + 1, r2, c1, c2));     for (int j = c1; j < c2; j++) {       ans = min(ans, fun(r1, r2, c1, j) + fun(r1, r2, j + 1, c2));     }     return dp[r1][r2][c1][c2] = ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; i += 1) cin >> g[i];     pre[0][0] = 1;     for (int i = 0; i < n; i++) {       pre[i][0] = pre[0][i] = 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (g[i][j] ==  # ) pre[i + 1][j + 1] = 1;         pre[i + 1][j + 1] += (pre[i][j + 1] + pre[i + 1][j] - pre[i][j]);       }     }     int ans = fun(1, n, 1, n);     cout << ans << endl;     return 0;   }   