Cod sursa(job #1583796)

Utilizator roxana_97Soare Roxana Florentina roxana_97 Data 29 ianuarie 2016 13:12:19
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<fstream>

using namespace std;
ifstream f("flip.in");
ofstream g("flip.out");

long long a[20][20],c[20],l[20],n,m,total, sum_col,fin,cop,stabil;

int main()
{
    f>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            f>>a[i][j];

        }
        fin = -(1<<30);
        for(int k=1;k<(1<<n);++k)
        {
            total =0;
            for (int j=1; j <= m; j++) {
                sum_col = 0;
                for (int i = 1; i <= n; i++) {
                    if (k&(1<<i)) {
                        sum_col -= a[i][j];
                    } else {
                        sum_col += a[i][j];
                    }
                }
                if (sum_col <0) sum_col *= -1;
                total += sum_col;
            }
            if (total >
                 fin) {
                fin = total;
            }
        }

    g<<fin<<'\n';
    f.close();g.close();
    return 0;
}