Pagini recente » Cod sursa (job #224226) | Cod sursa (job #833316) | Cod sursa (job #2210103) | Cod sursa (job #524715) | Cod sursa (job #2557758)
#include<iostream>
#include<fstream>
using namespace std;
ifstream in ("flip.in");
ofstream out("flip.out");
const int N = 16;
int mat[N][N];
int n, m;
inline int max(int x, int y)
{
return (x > y) ? x : y;
}
int sum(int cn, int cm)
{
int rez = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
{
bool negative_row = cn & (1 << i);
bool negative_col = cm & (1 << j);
bool negative = negative_row ^ negative_col;
rez += negative ? -mat[i][j] : mat[i][j];
}
return rez;
}
int main()
{
in >> n >> m;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
in >> mat[i][j];
int max_sum = sum(0, 0);
for(int cn = 1 << n - 1; cn >= 0; cn--)
for(int cm = 1 << m - 1; cm >= 0; cm--)
max_sum = max(max_sum, sum(cn, cm));
out << max_sum << '\n';
return 0;
}