Cod sursa(job #2959509)

Utilizator magicninjaJula Diana magicninja Data 31 decembrie 2022 15:57:03
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <iostream>
#include <fstream>

using namespace std;

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

long long a[17][17];

int main()
{
    int nc, nl, smax = -1000000, i, j, stotal, c, sc, l;
    in >> nl >> nc;
    for(i = 0; i < nl; i++){
        for(j = 0; j < nc; j++){
            in >> a[i][j];
        }
    }
    for(i = 0; i < (1 << nl); i++){
        stotal = 0;
        for(c = 0; c < nc; c++){
            sc = 0;
            for(l = 0; l < nl; l++){
                if(i & (1 << l)){
                    sc -= a[l][c];
                }
                else{
                    sc += a[l][c];
                }
            }
            if(sc < 0){
                sc =- sc;
            }
            stotal += sc;
        }
        smax = max(smax, stotal);
    }
    out << smax;
    return 0;
}