Cod sursa(job #91467)
#include<stdio.h>
#include<stdlib.h>
int n, t, max, best[3600];
typedef struct
{
int a, b, c;
} cutie;
cutie v[3600], a[3600];
int cmp(const void*a, const void*b)
{
long long int x=*(long long int*)a, y=*(long long int*)b;
if(v[x].a==v[y].a)
if (v[x].b==v[x].b) return v[x].c-v[y].c;
else return v[x].b-v[y].b;
else return v[x].a-v[y].a;
}
void calcul()
{
freopen("cutii.in","r",stdin);
freopen("cutii.out","w",stdout);
scanf ("%d %d", &n, &t);
int i, k, j, ord[3600];
for (k=1; k<=t; k++)
{
max=0;
for (i=1; i<=n; i++)
{ scanf("%d %d %d", &v[i].a, &v[i].b,&v[i].c); ord[i]=i;}
qsort(ord,n+1,sizeof(int),cmp);
for (i=1; i<=n; i++) a[i]=v[ord[i]], best[i]=0;
max=0;
best[n]=1;
for (i=n-1; i>=1; i--)
for (j=i+1; j<=n; j++)
{
if (a[j].a>a[i].a && a[j].b>a[i].b && a[j].c>a[i].c)
if (best[i]<=best[j]){ best[i]=best[j]+1; if (best[i]>max) max=best[i];}
if(best[i]==0) best[i]=1;
}
if (max==0) max=1;
printf("%d\n",max);
}
}
int main()
{
calcul();
return 0;
}