Cod sursa(job #604864)

Utilizator bocacristiBoca Nelu Cristian bocacristi Data 25 iulie 2011 18:22:28
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include<fstream>
using namespace std;

ifstream fin("flip.in");
ofstream fout("flip.out");

long int i,j,m,n,k,aux,b[1000],a[100][100],smat,s,max=-1;

int main()
{
    
    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;
	fin.close();
	fout.close();
	return 0;
}