Cod sursa(job #458950)

Utilizator andu.andr3yBoznea Andrei andu.andr3y Data 27 mai 2010 10:23:44
Problema Jocul Flip Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
Program flip; 
var f,g:text; a:array[1..16,1..16]of longint; 
b:array[1..16]of -1..1; 
i,j,m,n:byte; s,smax:longint; 
function maxim (x,y:longint):longint; 
begin
if x>y then exit (x) else exit (y); 
end; 
function sum:longint; 
var x,y:byte; z:longint; 
begin
s:=0; 
for x:=1 to n do begin  
z:=0; 
for y:=1 to m do z:=z+a[x,y]*b[y]; 
s:=s+abs (z);  
end; 
sum:=s; 
end; 
procedure calcul (x:byte); 
begin
if x=m then smax:=maxim (sum,smax) else begin
b[x+1]:=1; 
calcul (x+1); 
b[x+1]:=-1; 
calcul (x+1);  
end; 
end; 
begin
assign (f,'flip.in'); reset (f); 
assign (g,'flip.out'); rewrite (g); 
readln (f,n,m); 
for i:=1 to n do begin
for j:=1 to m do read (f,a[i,j]); 
readln (f); 
end; 
b[1]:=1; 
smax:=-maxlongint-1; 
calcul (1); 
writeln (g,smax); 
close (f); close (g); 
end.