Cod sursa(job #500354)

Utilizator andrey_porscheGraur Andrei andrey_porsche Data 11 noiembrie 2010 22:26:03
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<fstream>

 
using namespace std;
long int i,j,m,n,k,aux,b[1000],a[100][100],smat,s,max=-1;
int main()
{
   ifstream fin("flip.in");
    ofstream fout("flip.out");
    fin>>n;
    fin>>m;
    int max=-1;
    for(i=1;i<=n;i++)
       for(j=1;j<=m;j++)
          fin>>a[i][j];
for(i=0;i<(1<<n);i++)
   {
   aux=i;
  for(j=1;j<=n;j++)
       {
       b[j]=aux&1;
       aux>>=1;
       }
   smat=0;
   for(k=1;k<=m;k++)
       {
       s=0;
       for(j=1;j<=n;j++)
         {
          if(b[j])
            s+=a[j][k];
              else s-=a[j][k];
          }
      if(s<0)
         smat-=s;
           else smat+=s;
       }
    if(smat>max)
      max=smat;
    }
    fout<<max;
}