Leetcode 861. 翻转矩阵后的得分(DAY 117) ---- 贪心算法学习期
作者:互联网
原题题目
代码实现(首刷自解)
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;
}
};
标签:count,原题,861,ret,----,int,117,grid,Leetcode 来源: https://blog.csdn.net/qq_37500516/article/details/117020960