Cod sursa(job #3154048)

Utilizator David2007David Preda David2007 Data 2 octombrie 2023 21:36:46
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <bits/stdc++.h>

using namespace std;

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

long long int n,m,ma,mx,i,j,p,c;
long long int v[17][17];

int main()
{
    f>>n>>m;
    for(i = 1;i<=n;i++)
        for(j = 1;j<=m;j++)
            f>>v[i][j];
    for(ma = 0;ma<(1<<n);ma++)
    {
        long long s[m+1] = {0};
        for(i = 0;(1<<i) <= ma;i++)
        {
            p = 1;
            if(((1<<i) & ma) != 0)
                p = -1;
            for(j = 1;j<=m;j++)
                s[j] += v[i+1][j]*p;
        }
         c = 0;
        for(i = 1;i<=m;i++)
            c += max(s[i], -s[i]);
        mx = max(mx, c);
    }
    g<<mx;

    return 0;
}