Cod sursa(job #34976)

Utilizator CezarMocanCezar Mocan CezarMocan Data 21 martie 2007 18:19:41
Problema Cutii Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.22 kb
type cutie=record
                x,y,z:longint;
                end;
var v:array[1..3502]of cutie;
    x,zero:array[1..3502]of longint;
    t,i,j,k,n,max:longint;
    aux:cutie;

procedure qsort(ls,ld:longint);
var i,j:longint;
    aux:cutie;
begin
  i:=ls;j:=ld;
  while true do begin
    while (v[i].x<v[j].x)or((v[i].x=v[j].x)and(v[i].y<v[j].y))or
    ((v[i].x=v[j].x)and(v[i].y=v[j].y)and(v[i].z<v[j].z))
    and(i<>j) do inc(i);
    if i=j then break;
    aux:=v[i];v[i]:=v[j];v[j]:=aux;dec(j);
    while (v[i].x<v[j].x)or((v[i].x=v[j].x)and(v[i].y<v[j].y))or
    ((v[i].x=v[j].x)and(v[i].y=v[j].y)and(v[i].z<v[j].z))
    and(i<>j) do dec(j);
    if i=j then break;
    aux:=v[i];v[i]:=v[j];v[j]:=aux;inc(i);
  end;
  if j-1>ls then qsort(ls,j-1);
  if j+1<ld then qsort(j+1,ld);
end;

begin
assign(input,'cutii.in');reset(input);
assign(output,'cutii.out');rewrite(output);
readln(n,t);
for k:=1 to t do
        begin
        for i:=1 to n do
                readln(v[i].x,v[i].y,v[i].z);
        qsort(1,n);
{        for i:=1 to n-1 do
                for j:=i+1 to n do
                        if (v[i].x>v[j].x)or((v[i].x=v[j].x)and(v[i].y>v[j].y))or
                        ((v[i].x=v[j].x)and(v[i].y=v[j].y)and(v[i].z>v[j].z)) then
                                begin
                                aux:=v[i];
                                v[i]:=v[j];
                                v[j]:=aux;
                                end;}
        x:=zero;
        x[n]:=1;
        max:=1;
        for i:=n-1 downto 1 do
                begin
                x[i]:=1;
                for j:=i+1 to n do
                        if (v[i].x<v[j].x)and(v[i].y<v[j].y)and(v[i].z<v[j].z)then
                                begin
                                if x[i]<x[j]+1
                                        then x[i]:=x[j]+1;
                                if x[i]>max then
                                        begin
                                        max:=x[i];
                                        break;
                                        end;
                                end;
                   end;
        writeln(max);
        end;
close(input);close(output);
end.