Cod sursa(job #583210)

Utilizator mada0222Tomus Madalina mada0222 Data 18 aprilie 2011 22:01:51
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.56 kb
var
a:array[1..16,1..16] of longint;
n,m,i,j,k:longint;
suma,fin,s,ps:longint;
 f,g:text;
begin
assign(f,'flip.in');reset(f);
assign(g,'flip.out');rewrite(g);
readln(f,n,m);
fillchar(a,sizeof(a),0);
for i:=1 to n do
for j:=1 to m do
read(f,a[i][j]);
fin:= 1 shl m;
suma:=0;
for k:=1 to fin do begin
s:=0;
for i:=1 to n do begin
ps:=0;
for j:=1 to m do begin
if k and (1 shl j) > 0 then ps:=ps-a[i][j] else ps:=ps+a[i][j];
end;
if ps < 0 then s:=s-ps else s:=s+ps;
end;
if s > suma then suma:=s;
end;
writeln(g,suma);
close(f);
close(g);
end.