Cod sursa(job #964962)

Utilizator danlexDan Alexandru danlex Data 22 iunie 2013 20:18:53
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <iostream>
#include <fstream>
using namespace std;

int i, j, k, n, m, x, game[16][16], maxGame, sumGame = 0, sumCol = 0;

void read(){
    ifstream f("flip.in");
    f >> n;
    f >> m;

    for (i = 0; i < n; i++){
        for (j = 0; j < m; j++){
            f >> game[i][j];
        }
    }

    f.close();
}

void write(){
    ofstream of("flip.out");
    of << maxGame;
    of.close();

}

int computeGame(){
    sumGame = 0;
    for (j = 0; j < m; j++){
        sumCol = 0;
        for (i = 0; i < n; i++){
            sumCol += ((x & (1 << i)) ? -1 : 1) * game[i][j];
        }
        sumGame += (sumCol < 0) ? ((-1)*sumCol) : sumCol;
    }
    return sumGame;
}

void back(){
    for(x = 0; x < 1 << n; x ++){
        maxGame = max(maxGame, sumGame = computeGame());
    }
}

int main(void){
    read();
    back();
    write();
    return 0;
}