Cod sursa(job #1476320)

Utilizator dnprxDan Pracsiu dnprx Data 24 august 2015 22:05:06
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <bits/stdc++.h>

using namespace std;

int a[20][20], b[20][20], L, C;
int t[20], smax;

void Citire()
{
    int i, j;
    ifstream fin("flip.in");
    fin >> L >> C;
    for (i = 1; i <= L; i++)
        for (j = 1; j <= C; j++)
            fin >> a[i][j];
    fin.close();
}

void Rezolva()
{
    int i, j, n, stot, suma, x, y;
    n = (1 << C);
    for (i = 0; i < n; i++)
    {
        for (j = 1; j <= C; j++)
            if ((i & (1 << (j - 1))) == 0) t[j] = 0;
            else t[j] = 1;
        stot = 0;
        for (x = 1; x <= L; x++)
        {
            suma = 0;
            for (y = 1; y <= C; y++)
                if (t[y] == 0) suma += a[x][y];
                else suma -= a[x][y];
            if (suma < 0) stot -= suma;
            else stot += suma;
        }
        if (smax < stot) smax = stot;
    }

    ofstream fout("flip.out");
    fout << smax << "\n";
    fout.close();
}

int main()
{
    Citire();
    Rezolva();
    return 0;
}