原题题目
代码实现(首刷自解)
class Solution {
public:
int matrixScore(vector<vector<int>>& grid) {
int ret = 0;
for(int x=0;x<grid.size();++x)
{
if(grid[x][0]) continue;
else
{
for(int y=0;y<grid[0].size();++y)
grid[x][y] ^= 1;
}
}
ret += (1<<(grid[0].size()-1)) * grid.size();
for(int y=1;y<grid[0].size();++y)
{
int count = 0;
for(int x=0;x<grid.size();++x)
if(grid[x][y]) ++count;
ret += (1<<(grid[0].size()-1-y)) * (grid.size() >= 2*count ? grid.size()-count : count);
}
return ret;
}
};