Cod sursa(job #964956)

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

int i, j, k, n, m, st, x[100], game[16][16], localGame[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[i] ? -1 : 1) * game[i][j];
        }
        sumGame += (sumCol < 0) ? ((-1)*sumCol) : sumCol;
    }
    return sumGame;
}

void back(){
    st = 0;
    x[st] = -1;
    while (st >= 0) {
        if (x[st] < 1){
            x[st] ++;
            if (st == n -1){
                maxGame = max(maxGame, sumGame = computeGame());
            } else {
                st ++;
                x[st] = -1;
            }
        } else {
            st --;
        }
    }
}

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