Cod sursa(job #692314)

Utilizator tonyyy_14Ienciu Antoniu tonyyy_14 Data 26 februarie 2012 15:04:02
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <iostream>
#include<fstream>
using namespace std;


int main()
{
    long int i,j,m,n,k,aux,b[20],a[20][20],smat,s,max=0;

    ifstream in("flip.in");
    ofstream out("flip.out");
    in>>n;
    in>>m;
    for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
        {in>>a[i][j];
        max=max+a[i][j];
        }
    for(i=0;i<(1<<n);i++)
    {
        aux=i;
        for(j=1;j<=n;j++)
        {
            b[j]=aux&1;
            aux=aux/2;
        }
        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;
    }
    out<<max;
    in.close();
    out.close();
    return 0;
}