Pagini recente » Statistici FMI - Oprisan Andrei Daniel (AndreiOprisan) | Istoria paginii runda/hardest_contest_ever1/clasament | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #1993445)
#include <fstream>
using namespace std;
ifstream f("flip.in");
ofstream g("flip.out");
int a[20][20];
int n, m;
int stack[20];
long long Max = -16000000001;
/*void DisplayMatrix(long long copy_a[][20], int n, int m)
{
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= m;j++)
cout << copy_a[i][j] << " ";
cout << "\n";
}
}*/
/*void DisplayVector(int vec[], int size)
{
for (int i = 1;i <= size;i++)
cout << vec[i] << " ";
cout << "\n";
}*/
/*void CopyMatrix()
{
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
copy_a[i][j] = a[i][j];
}*/
/*long long ModifyColumn()
{
long long s;
long long sum = 0;
for (int j = 1;j <= m;j++)
{
s = 0;
for (int i = 1;i <= n;i++)
s += copy_a[i][j];
if (s > -s)
copy_a[0][j] = s;
else
copy_a[0][j] = -s;
sum += copy_a[0][j];
}
return sum;
}/*
/*void ModifyRow()
{
for (int i = 1;i <= n;i++)
if (stack[i])
for (int j = 1;j <= m;j++)
copy_a[i][j] *= -1;
}*/
long long solution()
{
long long sum = 0;
long long s;
for (int i = 1;i <= n;i++)
{
s = 0;
for (int j = 1;j <= m;j++)
if (stack[j])
s += a[i][j] * -1;
else
s += a[i][j];
if (s > -s)
sum += s;
else
sum += -s;
}
return sum;
}
void backtracking(int k)
{
if (k > m)
{
int x = solution();
//DisplayVector(stack, m);
//cout << "\n";
if (x > Max)
Max = x;
return;
}
stack[k] = 0;
backtracking(k + 1);
stack[k] = 1;
backtracking(k + 1);
}
int main()
{
f >> n >> m;
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
f >> a[i][j];
backtracking(1);
g << Max;
f.close();
g.close();
return 0;
}