Pagini recente » Cod sursa (job #2701797) | Cod sursa (job #348573) | Cod sursa (job #2420682) | Cod sursa (job #2622334) | Cod sursa (job #2558861)
#include<iostream>
#include<fstream>
using namespace std;
ifstream in ("flip.in");
ofstream out("flip.out");
const int N = 16;
int_fast32_t mat[N][N];
int n, m;
inline int_fast32_t max(int_fast32_t x, int_fast32_t y)
{
return (x > y) ? x : y;
}
int_fast32_t sum(int cn, int cm)
{
int_fast32_t rez = 0;
for(int i = 0; i < n; i++)
{
bool negative_row = cn & (1 << i);
int_fast32_t sum_row = 0;
for(int j = 0; j < m; j++)
{
bool negative_col = cm & (1 << j);
sum_row += negative_col ? -mat[i][j] : mat[i][j];
}
rez += negative_row ? -sum_row : sum_row;
}
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_fast32_t 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;
}