Pagini recente » Cod sursa (job #1695782) | Cod sursa (job #1080025) | Cod sursa (job #2781804) | Cod sursa (job #1421964) | Cod sursa (job #2457510)
#include <fstream>
#include <cstring>
using namespace std;
ifstream f("flip.in");
ofstream g("flip.out");
const int NMAX = 20;
int ans = -2e9;
int N, M, A[NMAX][NMAX], B[NMAX][NMAX];
bool Sel[NMAX];
static inline void Read ()
{
f.tie(NULL);
f >> N >> M;
for(int i = 1; i <= N; ++i)
for(int j = 1; j <= M; ++j)
f >> A[i][j];
return;
}
int main()
{
Read();
for(int i = 0; i < (1 << N); ++i)
{
memset(Sel, 0, sizeof(Sel));
for(int j = 0; j < N; ++j)
if(i & (1 << j))
Sel[j + 1] = true;
int Best = 0;
for(int l = 1; l <= N; ++l)
for(int c = 1; c <= M; ++c)
B[l][c] = A[l][c];
for(int l = 1; l <= N; ++l)
if(Sel[l])
for(int c = 1; c <= M; ++c)
B[l][c] = -A[l][c];
for(int c = 1; c <= M; ++c)
{
int Best1 = 0, Best2 = 0;
for(int l = 1; l <= N; ++l)
{
Best1 += B[l][c];
Best2 += -B[l][c];
}
Best += max(Best1, Best2);
}
ans = max(ans, Best);
}
g << ans << '\n';
return 0;
}