Cod sursa(job #65236)

Utilizator ProtomanAndrei Purice Protoman Data 7 iunie 2007 20:06:46
Problema Cutii Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.57 kb
var f1,f2:text; n,t,i,j,k,max,aux:longint; x,y,z,v:array[1..4000] of longint;
begin
        assign(f1,'cutii.in');
        reset(f1);
        assign(f2,'cutii.out');
        rewrite(f2);
        read(f1,n,t);
        for k:=1 to t do
        begin
                for i:=1 to n do
                        read(f1,x[i],y[i],z[i]);
                for i:=1 to n-1 do
                        for j:=i+1 to n do
                                if x[i]<x[j] then
                                begin
                                        aux:=x[i];
                                        x[i]:=x[j];
                                        x[j]:=aux;
                                        aux:=y[i];
                                        y[i]:=y[j];
                                        y[j]:=aux;
                                        aux:=z[i];
                                        z[i]:=z[j];
                                        z[j]:=aux;
                                end;
                for i:=n downto 1 do
                begin
                        max:=0;
                        for j:=i+1 to n do
                                if (x[i]>x[j])and(y[i]>y[j])and(z[i]>z[j])and(v[j]>max) then max:=v[j];
                        v[i]:=max+1;
                end;
                max:=0;
                for i:=1 to n do
                begin
                        if max<v[i] then max:=v[i];
                        v[i]:=0;
                end;
                writeln(f2,max);
        end;
        close(f1);
        close(f2);
end.