Cod sursa(job #8822)

Utilizator bacerandreiBacer Andrei bacerandrei Data 25 ianuarie 2007 17:51:43
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include<fstream.h>
long n,m,a[16][16],smax;
int main()
{
   long i,j,k,s,t;
  ifstream f("flip.in");
  ofstream g("flip.out");
   f>>n>>m;
   for(i=0;i<n;i++)
    for(j=0;j<m;j++)
     f>>a[i][j];
   for(i=0;i<(1<<m);i++)
    {
     s=0;
      for(k=0;k<n;k++)
       {
	for(t=j=0;j<m;j++)
	 if(i&(1<<j))
	  t+=-a[k][j];
	else
	 t+=a[k][j];
       s+=t<-t ?-t : t;
      }
     if(smax<s)
      smax=s;
    }
   g<<smax;
return 0;
}