Cod sursa(job #2853170)

Utilizator DooMeDCristian Alexutan DooMeD Data 19 februarie 2022 23:12:31
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int nmax = 16;

int n,m;
int a[nmax+5][nmax+5];
int sumcol[nmax+5];
ll mx;

void flip(int k) {
    for(int j=1; j<=m; j++) {
        a[k][j] *= -1;
        sumcol[j] += 2 * a[k][j];
    }
}

void compute() {
    ll s = 0;
    for(int j=1; j<=m; j++)
        s += 1LL * max(sumcol[j], -sumcol[j]);
    mx = max(mx,s);
}

void bt(int k) {
    if(k==n+1) {
        compute();
        return ;
    }
    bt(k+1);
    flip(k);
    bt(k+1);
}

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

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