Cod sursa(job #1779641)

Utilizator cristicretancristi cretan cristicretan Data 15 octombrie 2016 15:12:59
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <bits/stdc++.h>
#define NMax 17
using namespace std;

ifstream f("flip.in");
ofstream g("flip.out");

int n, st[NMax],m, s, mx = -12343, p;
long a[NMax][NMax];

void afisare()
{
    p = 0;
    for(int i = 1; i <= n; ++i)
    {
        s = 0;
        for(int j = 1; j <= m; ++j)
            s += a[i][j];
        p +=  abs(s);
    }
    if(mx < p) mx = p;
}

void comutare(int k)
{
    for(int i = 1; i <= n; ++i)
        a[i][k] = - a[i][k];
}

void back(int k)
{
    if(k == m) afisare();
        else
        {
            back(k + 1);
            comutare(k);
            back(k + 1);
        }
}

int main()
{
    f >> n >> m;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            f >> a[i][j];
    back(1);
    g << mx;
    return 0;
}