Pagini recente » Cod sursa (job #1666506) | Cod sursa (job #2843145) | Cod sursa (job #1536475) | Istoria paginii utilizator/amsasukeam | Cod sursa (job #1008073)
#include <iostream>
#include <fstream>
using namespace std;
int nr_linii , nr_coloane , matrix[17][17];
int solutie = 0;
bool sel[17];
int main()
{
ifstream input("flip.in");
ofstream output("flip.out");
input >> nr_linii >> nr_coloane;
for (int i = 0;i<nr_linii;i++)
for (int j = 0;j<nr_coloane;j++)
input >> matrix[i][j];
int max_v = 1 << nr_linii;
for (int i = 1;i<max_v;i++)
{
for (int j = 0;j<nr_linii;j++)
{
sel[j] = (1 << j) & i;
}
int s = 0;
for (int j = 0;j<nr_coloane;j++)
{
int sum_aux = 0;
for (int k = 0;k<nr_linii;k++)
if (sel[k]) sum_aux -= matrix[k][j];
else sum_aux += matrix[k][j];
if (sum_aux < 0) s += (-1) * sum_aux;
else s += sum_aux;
}
if (s > solutie) solutie = s;
}
output << solutie;
return 0;
}