Cod sursa(job #3211402)

Utilizator maftenoMaftei Alex-Cristian mafteno Data 9 martie 2024 11:23:21
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("flip.in");
ofstream fout("flip.out");
int n, m, b[20][20],a[20];

int main()
{
    int j, i,smax = INT_MIN,stot;
    fin >> n >> m;
    for (i = 1; i <= n; i++)
        for ( j = 1; j <= m; j ++)
            fin >> b[i][j];
    while (a[0] == 0)
    {
       stot = 0;
       int s;
       for ( i = 1; i <= n; i ++)
       {
           s = 0;
           for ( j = 1; j <= m; j ++)
                if(a[j] == 0) s+= b[i][j];
                else s -= b[i][j];
            stot += abs(s);
       }
        smax = max(smax,stot);
         for (j = m; a[j] == 1; j--)
            a[j] = 0;
        a[j] = 1;
    }
    fout <<smax <<" ";
    return 0;
}