Cod sursa(job #257303)

Utilizator andumMorie Daniel Alexandru andum Data 12 februarie 2009 23:45:17
Problema Cutii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <stdio.h>
#define NMAX 101

struct cutie{
	     int x,y,z;
	    };
cutie v[NMAX];
int n,t,i,j,l[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);
      quicksort(1,n);
      max=0;
      l[n]=1;
      for (j=n-1;j>=1;j--)
       {
	l[j]=1;
	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];
       }
      printf("%d\n", max);
     }
    
    return 0;          
    
}