Cod sursa(job #2649723)

Utilizator redstonegamer22Andrei Ion redstonegamer22 Data 16 septembrie 2020 00:12:34
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;

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

int n, m;
int mat[20][20];
int sp[20];

int maxim = -1000000000;

void bkt(int poz)
{
    //cout << poz << endl;
    if(poz == n)
    {
        int sum = 0;
        for(int j = 0; j < m; j++)
            sum += max(sp[j], -sp[j]);

        maxim = max(maxim, sum);
        return;
    }

    for(int j = 0; j < m; j++)
        sp[j] += mat[poz][j];

    bkt(poz+1);

    for(int j = 0; j < m; j++)
        sp[j] -= 2*mat[poz][j];

    bkt(poz+1);

    for(int j = 0; j < m; j++)
        sp[j] += mat[poz][j];
}

int main()
{
    in >> n >> m;

    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            in >> mat[i][j];

    bkt(0);

    out << maxim;
}