Cod sursa(job #2861241)

Utilizator mariog901Grigore Mario mariog901 Data 3 martie 2022 18:42:39
Problema Jocul Flip Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("flip.in");
ofstream fout("flip.out");
int a[100][100], max = 0, v[100], x, n, m;
void total() {
	int s1, stotala = 0,
		int i, j, max = 0;
	for (i = 1; i <= n; i++) {
		s1 = 0;
		for (j = 1; j <= m; j++) {
			s1 = s1 + v[i] * a[i][j];
			if (s1 < 0) {
				s1 = -s1;
			}
			stotala = stotala + s1;
		}
	}
	if (stotala> max) {
		max = stotala;
	}
}

void back(int x) {
	if (x < n) {
		total();
	}
	else {
		v[x] = 1;
		back(x + 1);
		v[x] = -1;
		back(x + 1);
	}

}

int main() {
	int i, j, n, m, max;
	fin >> n; fin >> m;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= m; j++)
		{
			fin >> a[i][j];
		}
	}
	back(1);
	fout<< max;
	fout.close();
	return 0;

}