Cod sursa(job #689802)

Utilizator DOru1995DorU FlorIN DOru1995 Data 24 februarie 2012 20:49:33
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>

using namespace std;
#include<fstream>
 

long int i,j,m,n,k,aux,b[1001],a[101][101],smat,s,max=-1;
int main()
{
	int max=-1;
ifstream in("flip.in");
ofstream out("flip.out");

in>>n;
in>>m;

for(i=1;i<=n;i++)
	for(j=1;j<=m;j++)
		in>>a[i][j]; 
	
	
for(i=0;i<(1<<n);i++)
	{
	aux=i;
	for(j=1;j<=n;j++)
	{
		b[j]=aux&1;
		aux>>=1;
	}
smat=0;
	for(k=1;k<=m;k++)
	{
	s=0;
		for(j=1;j<=n;j++)
			{
			if(b[j])
				s+=a[j][k];
			else
				s-=a[j][k];}
			if(s<0)
				smat-=s;
			else
				smat+=s;
	}
if(smat>max)
	max=smat;
}
out<<max;

in.close();
out.close();
return 0;
}