Cod sursa(job #414286)

Utilizator RoCkyRomila RoCky Data 9 martie 2010 21:47:04
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
#include <math.h>
using namespace std;
ifstream in("flip.in");
ofstream out("flip.out");
#define modul(n) (n>0?n:-n)
int rezmax=-32000,n,m;
int flip[17];
int a[17][17];
void calculeaza()
{   
	int rez=0,i,j;
	for(i=1;i<=n;i++)
	{
		int sum=0;
		for(j=1;j<=m;j++)
			sum+=a[i][j]*flip[j];
		rez+=abs(sum);
	}
	if(rez>rezmax)
		rezmax=rez;
}	
void back(int k)
{
	if(k-1==m)
		calculeaza();
	else
	{
		flip[k]=1;
		back(k+1);
		flip[k]=-1;
		back(k+1);
	}
}
int main ()
{
	int i,j;
	in>>n>>m;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			in>>a[i][j];
	back(1);
	out<<rezmax;
	return 0;
}