Pagini recente » Cod sursa (job #2047921) | Cod sursa (job #1246115) | Cod sursa (job #160935) | Cod sursa (job #976692) | Cod sursa (job #2293921)
#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 s1 = 0, s2 = 0;
for (int i = 1; i <= rows; ++i)
for (int j = 1; j <= cols; ++j)
if (i == r || j == c)
s1 += mat[i][j] * -1;
else
s1 += mat[i][j];
for (int j = 1; j <= cols; ++j)
for (int i = 1; i <= rows; ++i)
if (i == r || j == c)
s2 += mat[i][j] * -1;
else
s2 += mat[i][j];
s1 = max(s1, s2);
mx = max(mx, s1);
}
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;
}