Cod sursa(job #1008073)

Utilizator UnforgivenMihai Catalin Botezatu Unforgiven Data 10 octombrie 2013 10:11:48
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#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;
}