Pagini recente » Cod sursa (job #283283) | Cod sursa (job #1390613) | Cod sursa (job #174180) | Cod sursa (job #3220196) | Cod sursa (job #63229)
Cod sursa(job #63229)
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int b[1000];
void baza(int i)
{
int k=0;
while(i)
{
b[k++]=i%2;
i/=2;
}
//return k;
}
int main()
{
int n,m,i,j,max=0;
int a[100],mat[20][20];
FILE *in=fopen("flip.in","r");
fscanf(in,"%d%d",&n,&m);
for (i=0;i<n;++i)
for (j=0;j<m;++j)
fscanf(in,"%d",&mat[i][j]);
int mat_t[5][5];
int dan,put=(int)pow(2,m),tmp;
for(i=0;i<put;++i)
{
baza(i);
int s=0;
memset(a,0,n*sizeof(a[0]));
for(j=0;j<m;++j)
if (!b[j]) b[j]=-1;
//generat vectorul ; ma ocup de pozitii;
for (dan=0;dan<m;++dan)
{
//int s=0,s2=0;
for (tmp=0;tmp<n;++tmp)
a[tmp]+=(mat_t[tmp][dan]=mat[tmp][dan]*b[dan]);
/*
for (tmp=0;tmp<n;++tmp)
{
for (dan=0;dan<m;++dan)
printf("%d ",mat_t[tmp][dan]);
printf("\n");
}
*/
/*for (tmp=0;tmp<n;s+=a[tmp++][dan]);
for (tmp=0;tmp<n;s2+=a[tmp++][dan]*b[dan]);
printf("s=%d,s2=%d\n",s,s2);
if (s<s2)
{
for (tmp=0;tmp<n;mat_t[tmp++][dan]=mat[);
*/
}
for(tmp=0;tmp<n;tmp++)
if(a[tmp]<0)
s-=a[tmp];
else
s+=a[tmp];
if(s>max)
max=s;
//printf("\n");
}
fprintf(fopen("flip.out","w"),"%d\n",max);
return 0;
}