Cod sursa(job #326650)

Utilizator radu_cppRadu Voroneanu radu_cpp Data 25 iunie 2009 18:48:51
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <stdio.h>

int n,m,i,j,k,s,t,smax;
int a[20][20];

int main()
{
	freopen("flip.in","r",stdin);
	freopen("flip.out","w",stdout);
	scanf("%ld %ld",&n,&m);
	smax=0;
	for (i=1; i<=n; i++)
		for (j=1; j<=m; j++)
			scanf("%ld",&a[i][j]);
	for (i=0; i<1 << m ; i++)
	{
		s=0;
		for (k=1; k<=n; k++)
		{
			t=0;
			for (j=1; j<=m; j++)
				if (i & (1 << (j-1)))
					t-=a[k][j];
				else
					t+=a[k][j];
			if (t>-t)
				s+=t;
			else
				s-=t;
		}
		if (smax<s)
			smax=s;
	}
	printf("%ld",smax);
	fclose(stdin); fclose(stdout);
	return 0;
}