Cod sursa(job #2546900)

Utilizator OvidRata Ovidiu Ovid Data 14 februarie 2020 18:27:00
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul II Marime 0.81 kb
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ft first
#define sc second

ifstream fin("flip.in"); ofstream fout("flip.out");
int n, m, t[20][20];


long long suma_rand(int b, int i){
long long sum=0;

for(int j=0; j<m; j++){
    if(b&(1<<j) ){
        sum+=(-1)*t[i][j];
    }
    else{sum+=t[i][j];}
}

return max(sum, (-1)*sum );

}





long long suma_maxima(){
long long rez=0, s=0;


for(int b=1; b<(1<<m); b++){
    s=0;
    for(int i=0; i<n; i++){
        s+=suma_rand(b, i);
    }
rez=max(rez, s);

}




return rez;
}







//X-first, Y-second6 7 1 4
int main(){
fin>>n>>m;


for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
        fin>>t[i][j];
    }
}



fout<<suma_maxima();




return 0;
}