Cod sursa(job #282017)

Utilizator SprzlAbcdefg Sprzl Data 16 martie 2009 19:18:04
Problema Jocul Flip Scor 60
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.21 kb
program suma;
const fin = 'flip.in';
      fout = 'flip.out';
type stiva = array [1..16] of longint;
var i,j,k,n,m:byte;
    a:array [1..16,1..16] of longint;
    s:longint;
    st,rez:stiva;
procedure init;
begin
  st[k]:=3;
end;

function exista:boolean;
begin
 exista:=false;
 if (k<=n) and (st[k]>-1) then
 begin
   dec(st[k],2);
   exista:=true;
 end;
end;

function solutie:boolean;
begin
  solutie:=k=n;
end;

procedure prelucrare;
var t:longint;
begin
  fillchar(rez,sizeof(rez),0);
  t:=0;
  for i:=1 to k do
  begin
    for j:=1 to m do
    begin
      a[i,j]:=a[i,j]*st[i];
      inc(rez[j],a[i,j]);
    end;
  end;
  for i:=1 to m do
    inc(t,abs(rez[i]));
  if t>s then
    s:=t;
end;

procedure back;
begin
  k:=1;
  init;
  while k>0 do
  if exista then
  begin
    if solutie then
      prelucrare
    else
    begin
      inc(k);
      init;
    end;
  end
  else
    dec(k);
end;

begin
  {citire}
  assign(input,fin);
  assign(output,fout);
  reset(input);
  s:=-maxint;
  read(n,m);
  for i:=1 to n do
    for j:=1 to m do
      read(a[i,j]);
  back;
  {tipar}
  rewrite(output);
  write(s);
  close(input);
  close(output);
end.