Pagini recente » Cod sursa (job #1749716) | Cod sursa (job #1218859) | Cod sursa (job #968661) | Cod sursa (job #220233) | Cod sursa (job #2293910)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("flip.in");
ofstream fout ("flip.out");
int rows, cols, mat[17][17], mx = INT_MIN;
void calc(int r, int c) {
int s = 0;
for (int i = 1; i <= rows; ++i)
for (int j = 1; j <= cols; ++j)
if (i == r || j == c)
s += mat[i][j] * -1;
else
s += mat[i][j];
mx = max(mx, s);
}
void gen(int a, int b) {
calc(a, b);
if (a < rows)
gen(a + 1, b);
if (b < cols)
gen(a, b + 1);
}
int main() {
fin >> rows >> cols;
for (int i = 1; i <= rows; ++i)
for (int j = 1; j <= cols; ++j)
fin >> mat[i][j];
gen(1, 1);
fout << mx;
return 0;
}