Cod sursa(job #669308)

Utilizator psycho21rAbabab psycho21r Data 26 ianuarie 2012 18:56:04
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <fstream>
#define abs(a) (a > 0 ? a : a*(-1))

using namespace std;

int main()
{
    int n, m, t[16][16], max=0;
    bool a[16];
    ifstream in("flip.in");
    in >> n >> m;
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
        {
            in >> t[i][j];
            max += t[i][j];
        }
        a[i] = 0;
    }
	in.close();
    int t_b = 1<<n;
    for (int w = 0; w < t_b; ++w)
    {
        int sum_t = 0;
        for(int j = 0; j < m; ++j)
        {
            int sum_j = 0;
            for(int i = 0; i < n; ++i)
            {
                if(a[i])
                    sum_j -= t[i][j];
                else
                    sum_j += t[i][j];
            }
            sum_t+= abs(sum_j);
        }
        if (sum_t > max)
            max = sum_t;
        int f = 0;
        while(a[f])
        {
            a[f]=0;
            ++f;
        }
        a[f]=1;
    }
    ofstream out("flip.out");
    out << max;
    out.close();
    return 0;
}