Pagini recente » Cod sursa (job #2055797) | Cod sursa (job #1608558) | Cod sursa (job #1584804) | Cod sursa (job #2284627) | Cod sursa (job #3204788)
#include <bits/stdc++.h>
using namespace std;
ifstream in ("flip.in");
ofstream out ("flip.out");
int sol[20],a[20][20],n,m,maxim,sum,col;
void bk(int top)
{
if(top==n) {
int i,j;
sum=0;
for(j=1; j<=m; j++) {
col=0;
for(i=1; i<=n; i++) {
if(sol[i]==1) {
col+=a[i][j]*(-1);
} else {
col+=a[i][j];
}
}
if(col<col*(-1)) {
sum+=col*(-1);
} else {
sum+=col;
}
}
maxim=max(sum,maxim);
} else {
for(int i=0; i<=1; i++) {
sol[top]=i;
bk(top+1);
}
}
}
int main() {
int i,j;
in >> n >> m;
for (i=1; i<=n; i++){
for (j=1; j<=m; j++){
in >> a[i][j];
}
}
bk(1);
out << maxim;
return 0;
}