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