Cod sursa(job #20913)

Utilizator raduzerRadu Zernoveanu raduzer Data 22 februarie 2007 16:49:03
Problema Elimin Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.79 kb
var a:array[0..4000,0..4000]of integer;
    b,d:array[1..32]of integer;
    n,m,i,j,s,max,z,r,c,w:longint;


procedure lines;
var s,q,i,j:longint;
begin
     for i:=1 to n do d[i]:=0;
     for i:=1 to r do
     begin
          q:=2000000000;
          for j:=1 to n do
          begin
               if a[j][0]<q then q:=a[j][0];
          end;
          for j:=1 to n do
          begin
               if a[j][0]=q then
               begin
                    d[j]:=1;
                    break;
               end;
          end;
     end;
     s:=0;
     for i:=1 to n do
     begin
          if d[i]=0 then
               for j:=1 to m do
               begin
                    if b[j]=0 then s:=s+a[i][j];
               end;
     end;
     if s>max then max:=s;
end;



procedure back(i:integer);
var j:integer;
begin
     if i=c+1 then
     begin
          lines;
          exit;
     end;
     for j:=1 to m do
     begin
          if b[j]=0 then
          begin
               b[j]:=1;
               back(i+1);
               b[j]:=0;
          end;
     end;

end;

begin
     assign(input,'elimin.in');
     reset(input);
     assign(output,'elimin.out');
     rewrite(output);
     readln(n,m,r,c);
     s:=0;
     for i:=1 to n do
     begin
          for j:=1 to m do
          begin
               read(a[i][j]);
               w:=w+a[i][j];
          end;
          readln;
     end;
     if m>n then
     begin
          z:=m;
          m:=n;
          n:=z;
          z:=r;
          r:=c;
          c:=z;
     end;
     for i:=1 to n do
     begin
          s:=0;
          for j:=1 to m do s:=s+a[i][j];
          a[i][0]:=s;
     end;
     max:=0;
     z:=0;
     back(1);
     writeln(max);
close(output);
end.