Pagini recente » Cod sursa (job #1988611) | Cod sursa (job #496666) | Cod sursa (job #2272410) | Cod sursa (job #2423225) | Cod sursa (job #265410)
Cod sursa(job #265410)
#include<stdio.h>
long mat[16][16];
long max=0;
int sol[256];
int n,m,k=1;
void citire()
{
freopen("filip.in","r",stdin);
long man;
scanf("%d",&n);
scanf("%d",&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{scanf("%d",&man);mat[i][j]=man;}
}
void do_max()
{
long mat2[16][16];
int i,j;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
mat2[i][j]=mat[i][j];
long max2=0;
for(i=1;i<=n;i++)
if(sol[i])
for(j=1;j<=m;j++)
mat2[i][j]*=-1;
for(j=1;j<=m;j++)
if(sol[n+j])
for(i=1;i<=n;i++)
mat2[i][j]*=-1;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
max2+=mat2[i][j];
if(max2>max)max=max2;
}
add2sol()
{
int poz=1;
while(sol[poz]!=0)
sol[poz++]=0;
sol[poz]=1;
return poz<n+m;
}
int main()
{
freopen("filip.out","w",stdout);
while(add2sol())do_max();
printf("%ld\n",max);
return 1;
}