Cod sursa(job #604152)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 20 iulie 2011 17:18:24
Problema Cutii Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.69 kb
Program cutii;
 type dimens=record
              x,y,z:integer;
              end;
 var n,t,i,j,max,p,m:integer;
     a: array [1..3500] of dimens;
     b: array [1..3500] of integer;
     b1,b2:array [1..1 shl 17] of char;
     fi, fo:text;
 procedure qsort(l,r:integer);
  var i,j,k:integer;
      t:dimens;
  begin
   i:=l; j:=r;
   k:=a[(l+r) div 2].x;
    repeat
     while a[i].x>k do inc(i);
     While a[j].x<k do dec(j);
      if i<=j then begin
                  t:=a[i];
                  a[i]:=a[j];
                   a[j]:=t;
                   end;
      inc(i); dec(j);
    until i>=j;
  if j>l then qsort(l,j);
  if i<r then qsort(i,r);
 end;
begin
assign(fi,'cutii.in');
 assign(fo,'cutii.out');
settextbuf(fi,b1);
 settextbuf(fo,b2);
reset(fi);
rewrite(fo);
 readln(fi,n,t);
  for m:=1 to t do begin
               for i:=1 to n do readln(fi,a[i].x,a[i].y,a[i].z);
              qsort(1,n);
               b[n]:=1; max:=0;
                for i:=n-1 downto 1 do begin
                                     p:=i;
                                     for j:=i+1 to n do
                if ((a[j].x<a[i].x) and (a[j].y<a[i].y) and (a[j].z<a[i].z) and (b[j]>b[p]))
                or ((a[j].x>a[i].x) and (a[j].y>a[i].y) and (a[j].z>a[i].z) and (b[j]>b[p]))
                                   then p:=j;
                                     b[i]:=b[p]+1;
                                     if b[i]>max then max:=b[i];
                                     end;

               { for i:=1 to n do
                 if b[i]>max then max:=b[i];}
                  writeln(fo,max);
                for i:=1 to n-1 do b[i]:=0;
                 end;
  close(fo);
end.