Pagini recente » Diferente pentru problema/patrol2 intre reviziile 31 si 30 | Diferente pentru utilizator/nutaalexandru intre reviziile 47 si 46 | Diferente pentru tabele-hash-scurta-prezentare intre reviziile 5 si 4 | Diferente pentru problema/margiki intre reviziile 14 si 15 | Cod sursa (job #1608643)
#include <stdio.h>
#include <stdlib.h>
int m, n, s_max = -1;
int mat[16][16], v[16];
int abs(int x) { return x > 0 ? x : (-1) *x; }
int max(int a, int b) { return a > b ? a : b; }
void sum() {
int i, j, s, suma = 0;
for ( j = 0; j < m; j++ ) {
s = 0;
for ( i = 0; i < n; i++ )
s += mat[i][j] * v[i];
suma += abs(s);
}
s_max = max(suma,s_max);
}
void flip(int k) {
if ( k == n )
sum();
else {
v[k] = -1;
flip(k+1);
v[k] = 1;
flip(k+1);
}
}
int main()
{
freopen("flip.in","r",stdin);
freopen("flip.out","w",stdout);
scanf("%d %d",&n,&m);
int i, j;
for ( i = 0; i < n; i++ )
for ( j = 0; j < m; j++ )
scanf("%d",&mat[i][j]);
flip(0);
printf("%d",s_max);
return 0;
}