Cod sursa(job #1745617)

Utilizator B_RazvanBaboiu Razvan B_Razvan Data 22 august 2016 12:41:50
Problema Jocul Flip Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <iostream>
#include <cstdio>

using namespace std;

int n, m, a[20][20], sumcol[100], smax;

void citire()
{
    scanf("%d %d \n", &n, &m);
    for(int i=1; i<=n; ++i)
        for(int j=1; j<=m; ++j)
            scanf("%d", &a[i][j]);
}

void rezolvare()
{
    for(int i=1; i<(i<<n); ++i)
    {
        for(int g=1; g<=m; ++g)
            sumcol[g]=0;

        for(int g=1; g<=n; ++g)
            for(int j=1; j<=m; ++j)
                if(i&(1<<g-1))
                    sumcol[j]-=a[g][j];
                else
                    sumcol[j]+=a[g][j];

        int summat=0;
        for(int g=1; g<=m; ++g)
            if(sumcol[g]<0)
                summat-=sumcol[g];
            else
                summat+=sumcol[g];

        if(summat>smax)
            smax=summat;
    }
}
int main()
{
    freopen("flip.in", "r", stdin);
    freopen("flip.out", "w", stdout);
    citire();
    rezolvare();
    printf("%d", smax);
    return 0;
}