Cod sursa(job #2703475)

Utilizator Nitr0genVlad Ioan Nitr0gen Data 8 februarie 2021 16:50:30
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;


int n, m, a[16][16], c[16], ans = 0;


void backt(int k) {
	if(k == m) {
		int sum = 0;

		for(int i = 0; i < n; i++) {
			int now = 0;

			for(int j = 0; j < m; j++) {
				now += a[i][j] * c[j];
			}

			if(now < 0) now *= -1;

			sum += now;
		}

		ans = max(ans, sum);
	} else {
		c[k] = 1;
		backt(k + 1);

		c[k] = -1;
		backt(k + 1);
	}
}


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	freopen("flip.in", "r", stdin);
	freopen("flip.out", "w", stdout);

	cin >> n >> m;

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> a[i][j];

	backt(0);

	cout << ans << '\n';
}