Cod sursa(job #713704)

Utilizator ZancrowAugustin Zancrow Data 14 martie 2012 21:14:45
Problema Jocul Flip Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.32 kb
program flip;
type vector=array[1..100] of integer;
     tablou1=array[1..40,1..16] of longint;
     tablou2=array[1..40,1..16] of longint;
var m,n,i,j:integer;
    max:longint;
    a:vector;
    b:tablou1;
    c:tablou2;
    f,h:text;


     procedure heck;
         var x,y:integer;
         s:longint;
            begin
            s:=0;
            for x:=1 to n do for y:=1 to m do c[x,y]:=b[x,y];

            for x:=1 to n do if a[x]=1 then for y:=1 to m do c[x,y]:=c[x,y]*(-1);
            for x:=n+1 to n+m do if a[x]=1 then for y:=1 to n do c[y,x-n]:=c[y,x-n]*(-1);

            for i:=1 to n do for j:=1 to m do s:=s+c[i,j];
            if s>max then max:=s;
            end;

         procedure bin(p:integer);
         begin
         if (p>n+m) then heck else begin
                                  a[p]:=0;
                                  bin(p+1);
                                  a[p]:=1;
                                  bin(p+1);
                                  end;
                                  end;


 begin
 assign(f,'flip.in');
 reset(f);
 readln(f,n,m);
 for i:=1 to n do for j:=1 to m do readln(f,b[i,j]);
 for i:=1 to n do for j:=1 to m do max:=max+b[i,j];
 bin(1);
 assign(h,'flip.out');
 rewrite(h);
 writeln(h,max);
 close(f);
 close(h);
 end.