Cod sursa(job #1199095)

Utilizator ianic1999Ianic Umanschii ianic1999 Data 18 iunie 2014 09:35:47
Problema Jocul Flip Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.49 kb
type tabel=array[1..16,1..16]of longint;
var t,a:tabel;
    i,j,k,x,n,m,smax:longint;
procedure prelucrare(s,x:string);
 var sum,i,j,k:longint;
 begin
 for i:=1 to n do
 for j:=1 to m do
  a[i,j]:=t[i,j];

  sum:=0;
  for i:=1 to n do
   begin
    for j:=1 to m do
     begin
      if (s[i]='1')and(x[j]='0')then begin for k:=1 to m do a[i,k]:=a[i,k]*(-1)end
      else if (s[i]='0')and(x[j]='1')then begin for k:=1 to n do a[k,j]:=a[k,j]*(-1)end
 else if (s[i]='1')and(x[j]='1')then begin
                                      for k:=1 to m do a[i,k]:=a[i,k]*(-1);
                                      for k:=1 to n do a[k,j]:=a[k,j]*(-1);

                                        end;
    end;
   end;
   for i:=1 to n do
   for j:=1 to m do
   sum:=sum+a[i,j];
   if sum>smax then smax:=sum;
 end;
procedure cod2(s,x:string);
 begin
  if length(x)=m then prelucrare(s,x)
                  else
                   begin
                   cod2(s,x+'0');
                   cod2(s,x+'1');
                   end;
 end;
procedure cod1(s:string);
begin
 if length(s)=n then cod2(s,'')
                else
                 begin
                  cod1(s+'0');
                  cod1(s+'1');
                 end;
end;
begin
assign(input,'flip.in');
reset(input);
readln(n,m);
for i:=1 to n do
 begin
  for j:=1 to m do
  read(t[i,j]);
  readln;
 end;
close(input);

smax:=0;
cod1('');

assign(output,'flip.out');
rewrite(output);
write(smax);
close(output);
end.