Cod sursa(job #11667)
Utilizator | Diculescu Elena Alexandra portocala | Data | 1 februarie 2007 08:52:06 |
---|---|---|---|
Problema | Jocul Flip | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.41 kb |
#include<fstream.h>
long n,m,a[16][16],smax;
int main()
{long i,j,k,s,t;
ifstream f("flip.in");
f>>n>>m;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
f>>a[i][j];
f.close();
for(i=0;i<(1<<m);i++)
{s=0;
for(k=0;k<n;k++)
{for(t=j=0;j<m;j++)
if(i&(1<<j))t+=-a[k][j];
else t+=a[k][j];
s+=t<-t ? -t : t;
}
if(smax<s)smax=s;
}
ofstream g("flip.out");
g<<smax<<'\n';
g.close();
return 0;
}