Cod sursa(job #704836)

Utilizator viSuaL9Vladu Sorin viSuaL9 Data 2 martie 2012 21:00:10
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include<fstream>
#include<iostream>
using namespace std;
long int i,j,m,n,c,aux,x[1001],a[101][101],suma,s,max=-1;
int main()
{
	int max=-1;
ifstream f("flip.in");
ofstream g("flip.out");

f>>n;
f>>m;

for(i=1;i<=n;i++)
	for(j=1;j<=m;j++)
		f>>a[i][j];


for(i=0;i<(1<<n);i++)
	{
	aux=i;
	for(j=1;j<=n;j++)
	{
		x[j]=aux&1;
		aux=aux>>1;
	}

suma=0;
	for(c=1;c<=m;c++)
	{
	s=0;
		for(j=1;j<=n;j++)

			if(x[j])
				s+=a[j][c];
			else
				s-=a[j][c];
		if(s<0)

				suma-=s;
			else
				suma+=s;
	}
if(suma>max)
	max=suma;
}
g<<max;

f.close();
g.close();
return 0;
}