Cod sursa(job #2591253)

Utilizator RobertLISARURobert Lisaru RobertLISARU Data 30 martie 2020 06:45:14
Problema Jocul Flip Scor 100
Compilator cpp-32 Status done
Runda Arhiva de probleme Marime 0.68 kb
//Iterative solution

#include <fstream>

int n, m, t[16][16], colSum, tempSum, maxSum;

int main() {
	std::ifstream fin("flip.in");
	std::ofstream fout("flip.out");
	fin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; ) {
			fin >> t[i][j++];
		}
	}
	for (int flippedLinesBitMask = 0; flippedLinesBitMask < (1 << n); flippedLinesBitMask++) {
		tempSum = 0;
		for (int col = 0; col < m; col++) {
			colSum = 0;
			for (int line = 0; line < n; line++) {
				colSum += (flippedLinesBitMask&(1 << line)) ? -t[line][col] : t[line][col];
			}
			tempSum += abs(colSum);
		}
		maxSum = (tempSum > maxSum) ? tempSum : maxSum;
	}
	fout << maxSum;
	return 0;
}