Pagini recente » Cod sursa (job #832595) | Cod sursa (job #2931769) | Cod sursa (job #2086504) | Cod sursa (job #3281576) | Cod sursa (job #2429268)
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("flip.in");
ofstream fout("flip.out");
int a[100][100],n,m,suma,suma_total;
int calcul(){
int aux;
suma=0;
for(int i=1;i<=n;++i){
aux=0;
for(int j=1;j<=m;++j){
aux+=a[i][j];
}
if(aux<0){
aux*=(-1);
}
suma+=aux;
}
}
int bt(int k){
if(k>m){
calcul();
suma_total=max(suma_total,suma);
}else{
bt(k+1);
for(int i=1;i<=n;++i)
a[i][k]*=(-1);
bt(k+1);
}
}
int main(){
fin>>n>>m;
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
fin>>a[i][j];
bt(1);
fout<<suma_total;
fin.close();
fout.close();
}