Cod sursa(job #2398487)

Utilizator 1000Sabin Ilegitim 1000 Data 5 aprilie 2019 16:20:12
Problema Jocul Flip Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <fstream>

using namespace std;

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

int n, m, a[20][20];
int main()
{
    cin >> n >> m;

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

    int nmax = (1 << n) - 1;
    int mmax = (1 << m) - 1;

    int smax = 0;
    for(int i = 0; i <= nmax; i++)
        for(int j = 0; j <= mmax; j++)
        {
            int s = 0;
            for(int x = 0; x < n; x++)
                for(int y = 0; y < m; y++)
                {
                    int val = a[x][y];
                    if((1 << x) & i)
                        val *= -1;
                    if((1 << y) & j)
                        val *= -1;

                    s += val;
                }

            if(s > smax)
                smax = s;
        }

    cout << smax;

    return 0;
}