Cod sursa(job #2663189)

Utilizator KillHorizon23Orban Robert KillHorizon23 Data 25 octombrie 2020 16:02:54
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
ifstream fin("flip.in");
ofstream fout("flip.out");
ll n, m, mt[20][20], maxx = -1e6;
short sign[20];
void bak(int poz)
{
        if (poz == n + 1)
        {
                ll s = 0;
                for (int i = 1; i <= m; ++i)
                {
                        ll aux = 0;
                        for (int j = 1; j <= n; ++j)
                                aux += (mt[j][i] * sign[j]);
                        aux = abs(aux);
                        s += aux;
                }
                maxx = max(maxx, s);
        }
        else
               sign[poz] = 1, bak(poz + 1), sign[poz] = -1, bak(poz + 1);
}
int main()
{
        ios::sync_with_stdio(false);
        fin.tie();

        fin >> n >> m;
        for (int i = 1; i <= n; ++i)
                for (int j = 1; j <= m; ++j)
                        fin >> mt[i][j];
        bak(1);
        fout << maxx;

        return 0;
}