Cod sursa(job #3211389)

Utilizator mateilucaLuca Matei Gabriel mateiluca Data 9 martie 2024 11:14:35
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, a[20], b[20][20];

int main()
{
    int i, j, total, s, smax = INT_MIN;
    fin >> n >> m;
    for(i = 1;i <= n;i++)
        for(j = 1;j <= m;j++)
            fin >> b[i][j];
    while(a[0] == 0)
    {
        total = 0;
        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];
            total += abs(s);
        }
        smax = max(smax, total);
        for(j = m;a[j] == 1;j--)
            a[j] = 0;
        a[j] = 1;
    }
    fout << smax << "\n";
    fout.close();
    return 0;
}