Cod sursa(job #335388)

Utilizator Cata99Putan Catalin Cata99 Data 29 iulie 2009 20:14:06
Problema Jocul Flip Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.4 kb
#include<fstream.h>
int a[20][20],i,m,n,s;
int main()
{
long i,j,s1,r,t;
ifstream f("flip.in");
ofstream d("flip.out");
f>>n;
f>>m;
for (i=0;i<n;i++)
for (j=0;j<m;j++)f>>a[i][j];
for (r=0;r<(1<<m);r++)
{
s1=0;
for (i=0;i<n;i++)
{
for (t=j=0;j<m;j++)
if (r&(1<<j))t+=-a[i][j];
else t+=a[i][j];
if (t>-t)s1+=t;
else s1+=-t;
}
if (s1>s)s=s1;
}
d<<s;
return 0;
f.close();
d.close();
}