Cod sursa(job #3256268)

Utilizator MutewithFoxmutewithfox MutewithFox Data 13 noiembrie 2024 22:31:37
Problema Jocul Flip Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <bits/stdc++.h>
using namespace std;

#define ll long long

ifstream fin("flip.in");
ofstream fout("flip.out");
int n,m;
int a[17][17];
ll ans;


void sorvaltas(int sor)
{
    for(int j=1;j<=m;j++)
    {
        a[sor][j]= -a[sor][j];
    }
}

ll osszeg()
{
    ll osz=0;
    for(int j=1;j<=m;j++)
    {
        ll oszlop=0;
        for(int i=1;i<=n;i++)
        {
            oszlop+=a[i][j];
        }
        if(oszlop<0) osz+= -oszlop;
        else osz+= oszlop;
    }
    return osz;
}

void soronkent(int pos, bool isComuted) {
    if (pos == n + 1) {
        ans = max(ans, osszeg());
        return;
    }
    if (pos <= n && isComuted) {
        sorvaltas(pos);
    }
    soronkent(pos + 1, 0);
    soronkent(pos + 1, 1);
}

int main()
{
    fin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            fin>>a[i][j];
            // cout<<a[i][j]<<" ";
        }
        // cout<<"\n";
    }
    soronkent(0,0);
    fout<<osszeg();
    return 0;
}