やるだけ。
int f(vector<string> v) { int sum = 0; for (int i = 0; i < v.size(); ++i) { for (int j = 0; j < v[i].size(); ++j) { sum += v[i][j] == '1'; } } return sum; } class XorBoardDivTwo { public: int theMax(vector <string> B) { int mx = 0; const int H = B.size(); const int W = B[0].size(); for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { for (int k = 0; k < W; ++k) B[i][k] = (B[i][k] == '0' ? '1' : '0'); for (int k = 0; k < H; ++k) B[k][j] = (B[k][j] == '0' ? '1' : '0'); mx = max(mx, f(B)); for (int k = 0; k < W; ++k) B[i][k] = (B[i][k] == '0' ? '1' : '0'); for (int k = 0; k < H; ++k) B[k][j] = (B[k][j] == '0' ? '1' : '0'); } } return mx; } };