Cod sursa(job #2913480)

Utilizator mariusgMarius Gaibu mariusg Data 14 iulie 2022 18:32:37
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream fin("flip.in");
    ofstream fout("flip.out");
    
    int N, M;
    fin >> N >> M;
    long int a[N][M];
    
    for (int i=0; i<N; i++)
        for (int j=0; j<M; j++)
            fin >> a[i][j];
    
    int sum, s1, temp;
    for (int bt=0; bt<(1<<M); bt++)
    {
        s1=0;
        for (int i=0; i<N; i++)
        {
            temp=0;
            for (int j=0; j<M; j++) if (bt&(1<<j)) temp+=-a[i][j]; else temp+=a[i][j];
            if (temp<0) s1+=-temp; else s1+=temp;
        }
        if (s1>sum) sum=s1;
    }
    fout << sum;
}