Cod sursa(job #673674)

Utilizator ciuscatalincius catalin ciuscatalin Data 4 februarie 2012 19:38:53
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 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 f("flip.in");
    ofstream g("flip.out");
    f>>n;
    f>>m;
    int max=-1;
    for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
    f>>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;
        }
        g<<max;
        }