Cod sursa(job #1279395)

Utilizator nod_softwareBudisteanu Ionut Alexandru nod_software Data 30 noiembrie 2014 11:47:56
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul II Marime 1.23 kb
#include <fstream>

using namespace std;

const int lmax = 17;
int n , m , vArray[lmax + 1][lmax+ 1] , lin[lmax+ 1] , iSolve;

//-------------------------------------------------------------------------------------
void bkt(int p)
{
    if(p - 1 == n)
    {
        int s = 0 , s1;
        for(int i = 1 ; i <= m ; i++)
        {
            s1 = 0;
            for(int j = 1 ; j <= n ; j++)
                s1 += vArray[j][i] * lin[j];

            s += max(s1 , -s1);
        }

        iSolve= max(iSolve, s);
    }
    else
    {
        lin[p] = -1;
        bkt(p + 1);

        lin[p] = 1;
        bkt(p + 1);
    }
}
//-------------------------------------------------------------------------------------
void ReadData()
{
    ifstream in("flip.in");

    in >> n >> m;

    for(int i = 1 ; i <= n ; i++)
        for(int j = 1 ; j <= m ; j++)
            in >> vArray[i][j];
}
//-------------------------------------------------------------------------------------
int main()
{
    iSolve = -1000000005;

    ReadData();

    bkt(1);

    ofstream out("flip.out");

    out << iSolve<< '\n';
    return 0;
}
//-------------------------------------------------------------------------------------