Cod sursa(job #65513)
#include <cstdio>
#include <algorithm>
#define maxn 3500
using namespace std;
FILE *in = fopen("cutii.in","r"), *out = fopen("cutii.out","w");
struct cutie
{
int x, y, z;
};
int n, t;
cutie a[maxn];
int lis()
{
int max = 0;
int l[maxn];
for ( int i = 0; i < n; ++i )
{
l[i] = 1;
for ( int j = 0; j < i; ++j )
if ( l[i] < l[j] + 1 && a[j].y < a[i].y && a[j].z < a[i].z )
l[i] = l[j] + 1;
if ( l[i] > max )
max = l[i];
}
return max;
}
bool operator<(const cutie &x, const cutie &y) {
return x.x < y.x;
}
int main()
{
fscanf(in, "%d %d", &n, &t);
while ( t )
{
for ( int i = 0; i < n; ++i )
fscanf(in, "%d %d %d", &a[i].x, &a[i].y, &a[i].z);
sort(a, a+n-1);
fprintf(out, "%d\n", lis());
--t;
}
return 0;
}