Pagini recente » Cod sursa (job #3122322) | Cod sursa (job #2267851) | Cod sursa (job #2511669) | Cod sursa (job #2968579) | Cod sursa (job #2277817)
#include <bits/stdc++.h>
using namespace std;
int v[17][17],flip[17],n,m,mx=-1000000000;
int func(){
int s=0,i,sum;
for(i=1;i<=m;i++) {
sum=0;
for(j=1;j<=n;j++)
if(flip[j]!=0)
sum+=(-v[j][i]);
else
sum+=v[j][i];
s+=max(sum,-sum);
}
return s;
}
int main (){
freopen("flip.in","r",stdin);
freopen("flip.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
scanf("%d",v[i][j]);
for(i=1;i<(1<<n);i++){
for(j=0;(1<<j)<=i;j++)
if((1<<j)&i!=0)
flip[j+1]=1;
else
flip[j+1]=0;
mx=max(mx,func());
}
cout<<mx;
return 0;
}