Cod sursa(job #2450697)

Utilizator Gabi_LazaLaza Gabriel Gabi_Laza Data 24 august 2019 12:15:41
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>
#define NMAX 20
using namespace std;
ifstream in("flip.in");
ofstream out("flip.out");

int n, m, a[NMAX][NMAX];
long long s;

void read() {
    in >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            in >> a[i][j];
}

void back(int k) {
    if(k > m) {
        long long s1 = 0;
        for(int i = 1; i <= n; i++) {
            int x = 0;
            for(int j = 1; j <= m; j++)
                x += a[i][j];
            if(x < 0)
                x = -x;
            s1 += x;
        }
        if(s < s1)
            s = s1;
    }
    else {
        back(k+1);
        for(int i = 1; i <= n; i++)
            a[i][k] = -a[i][k];
        back(k+1);
    }
}

int main() {
    read();
    back(1);
    out << s;

    in.close();
    out.close();
    return 0;
}