Cod sursa(job #265777)

Utilizator warangeldinu sorin warangel Data 24 februarie 2009 14:31:08
Problema Jocul Flip Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include<stdio.h>
long mat[16][16];
long max =-1099999999;
int sol[16];
int n,m;
void citire()
{
	freopen("flip.in","r",stdin);
   scanf("%d",&n);
   scanf("%d",&m);
   for(int i=1;i<=n;i++)
      for(int j=1;j<=m;j++)
         scanf("%ld",&mat[i][j]);
}

long suma_col(int col)
{
	long s=0;int x;
   for(int i=1;i<=n;i++)
      {if(sol[i])x=-1;else x=1;s+=mat[i][col]*x;}
   if(s>0)return s;
   else return -s;
}

void do_max()
{
   int i;
   long max2=-1099999999;
   for(i=1;i<=m;i++)
      max2+=suma_col(i);
   if(max2>max)max=max2;
}
int add2sol()
{
   int poz=1;
   while(sol[poz]!=0)
      sol[poz++]=0;
   sol[poz]=1;
   return poz<=n+1;
}
int main()
{
   freopen("flip.out","w",stdout);
   citire();
   while(add2sol())do_max();
   printf("%ld",max);
   return 0;
}