Cod sursa(job #2386792)

Utilizator oogaboogauvuvwevwevwe onyetenyevwe ugwemubwem ossas oogabooga Data 23 martie 2019 17:52:39
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>

using namespace std;

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

int n, m, a[17][17], MX;

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

    for(int i = 0; i < (1 << n); ++i)
    {
        int S = 0;
        for(int y = 1; y <= m; ++y)
        {
            int s = 0;
            for(int x = 1; x <= n; ++x)
                if(i >> (x-1) & 1 == 1)
                    s -= a[x][y];
                else
                    s += a[x][y];
            S += abs(s);
        }
        MX = max(MX, S);
    }

    out<<MX;

    return 0;
}