Cod sursa(job #194808)

Utilizator edy_3dzEdy 3dz edy_3dz Data 14 iunie 2008 12:40:04
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream.h>

ifstream f("flip.in");
ofstream g("flip.out");
int n,m,a[17][17],max=0,c[17];

void calc()
{
 int j,i,temp,s=0;
 for (j=1;j<=m;j++)
  {
   temp=0;
   for (i=1;i<=n;i++)
	temp=temp+c[i]*a[i][j];
   if (temp<0) s=s-temp;
	else s+=temp;
  }
 if (s>max) max=s;
}

void bkt(int k)
{
 if (k==n+1) calc();
  else
 for (int aux=-1;aux<=1;aux+=2)
  {
   c[k]=aux;
   bkt(k+1);
  }
}

int main()
{
 f>>n>>m;
 int i,j;
 for (i=1;i<=n;i++)
  for (j=1;j<=m;j++)
   {
	f>>a[i][j];
	max+=a[i][j];
   }
 bkt(1);
 g<<max<<'\n';
 return 0;
}