Cod sursa(job #7903)

Utilizator IgnitionMihai Moraru Ignition Data 22 ianuarie 2007 22:05:26
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <stdio.h>
#include <algorithm>

using namespace std;

#define MN (3501)

struct cutie {
	short x, y, z;
	inline bool operator<(const cutie &c2) const
	{
		return this->x < c2.x;
	}
};

inline int fits(cutie &c1, cutie &c2)
{
	return (c1.x < c2.x && c1.y < c2.y && c1.z < c2.z);
}

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

	cutie n[MN];
	short c[MN];
	short N, T, X, i, j;

	for(scanf("%hd %hd", &N, &T); T --; ) {
		for(i = 0; i < N; ++ i)
			scanf("%hd %hd %hd", &n[i].x, &n[i].y, &n[i].z);
		/*
		for(i = 0; i < N; ++ i)
			printf("%d %d %d\n", n[i][0], n[i][1], n[i][2]); printf("\n");
			*/
		sort(n, n+N);
		/*
		for(i = 0; i < N; ++ i)
			printf("%d %d %d\n", n[i][0], n[i][1], n[i][2]); printf("\n");
			*/
		for(X = c[0] = i = 1; i < N; ++ i) for(c[i] = 1, j = 0; j < i; ++ j) if(c[j]+1 > c[i] && fits(n[j], n[i]))
			c[i] = c[j]+1;
		for(i = 0; i < N; ++ i) if(c[i] > X)
			X = c[i];
		printf("%hd\n", X);
	}

	return 0;
}