Cod sursa(job #257234)

Utilizator andumMorie Daniel Alexandru andum Data 12 februarie 2009 22:38:55
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <stdio.h>
#define NMAX 3501

struct cutie{
	     short x,y,z;
	     };
cutie v[NMAX];
short n,t,i,j,l[NMAX],p[NMAX],max,h;

void quicksort(int st, int dr)
{
     int i,j,p;

     i=st; j=dr; p=(i+j)/2;
     if (i>=j) return;
      else
     while (i<=j)
           {
                 while (v[i].z<p) i++;
                 while (v[j].z>p) j--;
                 if (i<=j)
                    {
                     v[0]=v[i];
                     v[i]=v[j];
                     v[j]=v[0];
                     i++;
                     j--;
                    }
                 if (st<j) quicksort(st,j);
                 if (dr>i) quicksort(i,dr);
           }
}

int main()
{
    freopen("cutii.in","r",stdin);
    freopen("cutii.out","w",stdout);
    
    scanf("%d %d", &n, &t);
    for (i=1;i<=t;i++)
     {
      for (j=1;j<=n;j++)
	  {
	   scanf("%d %d %d", &v[j].x, &v[j].y, &v[j].z);
           l[j]=1;
           p[j]=-1;
          } 
      quicksort(1,n);
      max=0;
      for (j=n-1;j>=1;j--)
       for (h=j+1;h<=n;h++)
           if (v[j].x<v[h].x && v[j].y<v[h].y && l[j]<l[h]+1)
              {
                 l[j]=l[h]+1;
                 if (l[j]>max) max=l[j];
                 p[j]=h;
              }
      printf("%d\n", max);
     }
    
    return 0;          
    
}