先写的状压,因为数据说只有<=20 然后挂了。。
贪心
class Solution {
public:int matrixScore(vector<vector<int>>& A) {if (!A.size() || !A[0].size()) return 0;for (int i = 0; i < A.size(); i++) {if (!A[i][0]) {for (int j = 0; j < A[i].size(); j++) {A[i][j] = !A[i][j];}}}int ret = 0;for (int j = 0; j < A[0].size(); j++) {int cnt = 0;for (int i = 0; i < A.size(); i++) {if (A[i][j])cnt ++;}if (cnt < (A.size()+1)/2) {for (int i = 0; i < A.size(); i++) {A[i][j] = !A[i][j];}}}for (int i = 0; i < A.size(); i++) {int tmp = 0;for (int j = 0; j < A[i].size(); j++) {if (A[i][j]) {tmp |= 1 << (A[i].size()-1-j);}}ret += tmp;}return ret;}
};