Cod sursa(job #1274932)

Utilizator lokixdSebastian lokixd Data 24 noiembrie 2014 16:23:13
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 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=0;
   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;
   //printf("poz: %d ; ",poz);
   return poz<=n;
}
void tip_sol()
{
   for(int i=1;i<=n;i++)printf("%d ",sol[i]);
   printf("\n");
}
int main()
{
   freopen("flip.out","w",stdout);
   citire();
   do
   {
      //tip_sol();
      do_max();
   }
   while(add2sol());
   printf("%ld",max);
   return 0;
}