Cod sursa(job #222402)

Utilizator CezarMocanCezar Mocan CezarMocan Data 22 noiembrie 2008 12:03:51
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <cstdio>
#include <algorithm>
#include <cstring>
#define MAXN 3510

using namespace std;

struct cutie {
	int x, y, z;
};

int n, t, i, j, rez, x[MAXN];
cutie v[MAXN];

bool cmp(cutie a, cutie b) {
	if ((a.z < b.z) || ((a.z == b.z) && (a.x < b.x)) || ((a.z == b.z) && (a.x == b.x) && (a.y < b.y))) 
		return true;
	else
		return false;
}

bool cmp2(cutie a, cutie b) {
	if (a.x < b.x && a.y < b.y && a.z < b.z)
		return true;
	else
		return false;
}

void read() {
	int i;
	memset(v, 0, sizeof(v));
	memset(x, 0, sizeof(x));
	rez = 0;

	for (i = 1; i <= n; i++)
		scanf("%d%d%d", &v[i].x, &v[i].y, &v[i].z);

	sort(v + 1, v + n + 1, cmp);
}

void solve() {
	int i, j;
	rez = 0;
	x[1] = 1;

	for (i = 2; i <= n; i++)
		for (j = 1; j < i; j++)
			if (cmp2(v[j], v[i]) && (x[j] + 1 > x[i]))
				x[i] = x[j] + 1;

	for (i = 1; i <= n; i++)
		if (x[i] > rez)
			rez = x[i];
}

int main() {
	freopen("cutii.in", "r", stdin);
	freopen("cutii.out", "w", stdout);

	scanf("%d%d", &n, &t);

	for (i = 1; i <= t; i++) {
		read();
		solve();
		printf("%d\n", rez);
	}

	return 0;
}