Cod sursa(job #615929)

Utilizator ZbintiosulRacu Mihai Zbintiosul Data 11 octombrie 2011 12:53:09
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda info_20_b Marime 0.64 kb
#include <iostream>
#include <limits.h>
#include <fstream>
using namespace std;

int n, m, a[16][16], x = LONG_MIN;
int row[16];

void rez()
{
	int s1 = 0, s, i, j;
	for(j = 0; j < m; ++j, s1+= s) {
		for(s=i=0; i<n; ++i)
			s += a[i][j]*row[i];
		 if (s < 0) s=-s;
	}
	if (s1 > x) x=s1;
}

void apl(int k)
{
	if(k >= n)
		rez();
	else {
		row[k] = -1;
		apl(k+1);
		row[k] = 1;
		apl(k+1);
	}
}

int main()
{
	int i, j;
	ifstream f1 ("flip.in");
    ofstream f2 ("flip.out");
	f1>>n>>m;
	for(i = 0; i < n; ++ i)
		for(j = 0; j < m; ++ j)
			f1>>a[i][j];
	f1.close();
	apl(0);
	f2<<x;
    f1.close();
	return 0;
}