Pagini recente » Cod sursa (job #769421) | Cod sursa (job #156409) | Cod sursa (job #2591460) | Cod sursa (job #1619010) | Cod sursa (job #178149)
Cod sursa(job #178149)
#include <stdio.h>
#include <stdlib.h>
#define maxn 3501
int n, T;
int best[maxn], v[maxn];
struct cutie {
int x, y, z;
} c[maxn];
int cmp(const void *a, const void *b)
{
cutie *aa = (cutie *)a, *bb = (cutie *)b;
if (aa->x - bb->x)
return aa->x - bb->x;
if (aa->y - bb->y)
return aa->y - bb->y;
return aa->z - bb->z;
}
int main()
{
int i, j;
FILE *fin = fopen("cutii.in", "rt"), *fout = fopen("cutii.out", "wt");
fscanf(fin, "%d %d", &n, &T);
for (; T; T--)
{
for (i = 1; i <= n; i++)
fscanf(fin, "%d %d %d", &c[i].x, &c[i].y, &c[i].z);
qsort(c, n + 1, sizeof(cutie), cmp);
for (i = 1; i <= n; i++)
{
best[i] = 1;
for (j = i - 1; j > 0 && v[j] >= best[i]; j--)
if (c[i].x > c[j].x && c[i].y > c[j].y && c[i].z > c[j].z)
if (best[i] < best[j] + 1)
best[i] = best[j] + 1;
v[i] = best[i] > v[i - 1] ? best[i] : v[i - 1];
}
/* for (i = 1; i <= n; i++)
fprintf(fout, "%d %d %d\n", c[i].x, c[i].y, c[i].z);
for (i = 1; i <= n; i++)
fprintf(fout, "%d ", best[i]);
fprintf(fout, "\n");
for (i = 1; i <= n; i++)
fprintf(fout, "%d ", v[i]);
fprintf(fout, "%d\n");*/
fprintf(fout, "%d\n", v[n]);
}
fclose(fin), fclose(fout);
return 0;
}