Cod sursa(job #1246203)

Utilizator lacraruraduRadu Matei Lacraru lacraruradu Data 20 octombrie 2014 19:22:06
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>

using namespace std;

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

const int lcmax = 16;
int n , m , v[lcmax + 1][lcmax + 1] , lin[lcmax + 1] , smax;

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 += v[j][i] * lin[j];

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

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

int main()
{
    smax = -1000000000;

    in >> n >> m;

    for(int i = 1 ; i <= n ; i++)
        for(int j = 1 ; j <= m ; j++)
            in >> v[i][j];

    bkt(1);

    out << smax << '\n';
    return 0;
}