Cod sursa(job #1595613)

Utilizator garovatGarovat Adrian garovat Data 10 februarie 2016 13:51:29
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <iostream>
#include <fstream>


using namespace std;

ifstream in("flip.in");
ofstream out("flip.out");
int **mat, m, n, sum;

void citire(){
    in >> n >> m;
    mat = new int*[n];
    for(int i = 0; i < n; i++){
        mat[i] = new int[m];
        for(int j = 0; j < m; j++)
            in >> mat[i][j];
    }
}

void rezolvare(){
    int col, row;
    for(int c = 0; c < (1 << n); c++){
        col = 0;
        for(int i = 0; i < m; i++){
            row = 0;
            for(int j = 0; j < n; j++){
                row += (((1 << j) & c) ? 1 : -1) * mat[j][i];
            }
            col += row < 0 ? -row : row;
        }
        if(col > sum)
            sum = col;
    }
}

void scriere(){
    out << sum;
}

int main()
{
    citire();
    rezolvare();
    scriere();
    return 0;
}