Pagini recente » Cod sursa (job #816506) | Cod sursa (job #793730) | Cod sursa (job #719099) | Cod sursa (job #787954) | Cod sursa (job #2094660)
#include <cstdio>
#define maxn 3500
FILE *in = fopen("cutii.in","r"), *out = fopen("cutii.out","w");
struct cutie
{
int x, y, z;
};
int n, t;
cutie a[maxn];
int partition(int top, int bottom)
{
cutie x = a[top];
int i = top - 1;
int j = bottom + 1;
cutie temp;
do
{
do
{
--j;
} while ( x.x < a[j].x );
do
{
++i;
} while ( x.x > a[i].x );
if ( i < j )
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
} while ( i < j );
return j;
}
void qs(int top, int bottom)
{
int middle;
if ( top < bottom )
{
middle = partition(top, bottom);
qs(top, middle);
qs(middle+1, bottom);
}
}
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 and a[j].y < a[i].y and a[j].z < a[i].z )
l[i] = l[j] + 1;
if ( l[i] > max )
max = l[i];
}
return max;
}
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);
qs(0, n-1);
fprintf(out, "%d\n", lis());
--t;
}
return 0;
}