Pagini recente » Cod sursa (job #344122) | Cod sursa (job #2280511) | Cod sursa (job #939572) | Cod sursa (job #335173) | Cod sursa (job #3254185)
#include <iostream>
#include <set>
#include <algorithm>
#include <fstream>
using namespace std;
ifstream fin("flip.in");
ofstream fout("flip.out");
int n, m, mt[17][17];
long long ans;
void changeLine(int line) {
for (int j = 1; j <= m; ++j) {
mt[line][j] = -mt[line][j];
}
}
long long computeSum() {
long long sum = 0;
for (int j = 1; j <= m; ++j) {
long long colSum = 0;
for (int i = 1; i <= n; ++i) {
colSum += mt[i][j];
}
if (colSum < 0) {
sum += -colSum;
} else {
sum += colSum;
}
}
return sum;
}
void genAns(int pos, bool isComuted) {
if (pos == n + 1) {
ans = max(ans, computeSum());
return;
}
if (pos <= n && isComuted) {
changeLine(pos);
}
genAns(pos + 1, 0);
genAns(pos + 1, 1);
}
int main() {
fin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
fin >> mt[i][j];
}
}
genAns(0, 0);
fout << ans;
return 0;
}