Cod sursa(job #1990217)

Utilizator cc4infinityCojocaru Catalin cc4infinity Data 10 iunie 2017 20:06:50
Problema Jocul Flip Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.79 kb
var a,b,n,i,m,j,x,y:longint;
    s:string[20];
    t:array[1..20,1..20] of longint;

procedure max(s:string);
var b1,b,i,j:longint;
 begin
  b1:=0;
  for i:=1 to m do
   begin
    b:=0;
    for j:=1 to n do
     if s[j]='1' then b:=b-t[j,i] else b:=b+t[j,i];
    if -b>b then b:=-b;
    b1:=b1+b;
   end;
  if b1>x then x:=b1;
 end;

procedure gen(s:string);
begin
if length(s)<n then begin
                     gen(s+'0');
                     gen(s+'1');
                    end
               else max(s);
end;



begin
assign(input,'flip.in');
reset(input);
readln(n,m);
for i:=1 to n do
 for j:=1 to m do
  begin
   read(t[i,j]);
   if j=m then readln;
  end;
close(input);
s:='';
gen(s);
assign(output,'flip.out');
rewrite(output);
write(x);
close(output);
end.