Pagini recente » Cod sursa (job #2550174) | Cod sursa (job #3151916) | Cod sursa (job #3273738) | Cod sursa (job #2720126) | Cod sursa (job #670875)
Cod sursa(job #670875)
#include<iostream>
#include<fstream>
using namespace std;
ifstream ifile;
ofstream ofile;
int a,b,i,j,best=0,m[20][16],bk[20];
void resolve(){
int x,s=0;
for(j=1;j<=b;j++){
x=0;
for(i=1;i<=a;i++){
x = x + bk[i]*m[i][j];
}
if(x<0) s -= x;
else s += x;
}
if(s>best) best = s;
}
void bktr(int k){
if(k==a+1) resolve();
else {
bk[k] = -1;
bktr(k+1);
bk[k] = 1;
bktr(k+1);
}
}
int main(){
ifile.open("flip.in");
ifile>>a>>b;
for(i=1; i<=a; i++){
for(j=1; j<=b; j++){
ifile>>m[i][j];
best += m[i][j];
}
}
ifile.close();
bktr(1);
ofile.open("flip.out");
ofile<<best;
ofile.close();
return 0;
}