Pagini recente » Cod sursa (job #1999011) | Cod sursa (job #2114559) | Cod sursa (job #913552) | Cod sursa (job #1479283) | Cod sursa (job #409609)
Cod sursa(job #409609)
#include <stdio.h>
int v[17][17],sumac=0,max=0,n,m,li[17],stotal=0,k;
void brak(int k){
int i,j;
if(k==n+1){
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
stotal=stotal+v[i][j]*li[i];
}
}
for(i=1;i<=m;i++){
for(j=1;j<=n;j++){
sumac=sumac+v[j][i]*li[j];
}
if(sumac<0){
stotal=stotal-2*sumac;
}
sumac=0;
}
if(stotal>=max){
max=stotal;
}
stotal=0;
sumac=0;
}else{
li[k]=1;
brak(k+1);
li[k]=-1;
brak(k+1);
}
}
int main()
{
freopen("flip.in","r",stdin);
freopen("flip.out","w",stdout);
scanf("%d%d",&n,&m);
int y,l;
for(y=1;y<=n;y++){
for(l=1;l<=m;l++){
scanf("%d",&v[y][l]);
}
}
brak(1);
printf("%d",max);
return 0;
}