Cod sursa(job #354943)

Utilizator Spike7d8Cristian Varvara Spike7d8 Data 9 octombrie 2009 22:04:37
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;


struct Cutie
{
	int x, y, z;

	bool operator < (const Cutie &cutie) const
	{
		if (x < cutie.x)
			return true;
		if (x > cutie.x)
			return false;
		if (y < cutie.y)
			return true;
		if (y > cutie.y)
			return false;
		if (z < cutie.z)
			return true;
		return false;
	}
};


bool intra(const Cutie &c1, const Cutie &c2)
{
	if (c1.y < c2.y && c1.z < c2.z)
		return true;
	return false;
}


Cutie cutie[4096];
int best[4096];


int main()
{
	freopen("cutii.in", "rt", stdin);
	freopen("cutii.out", "wt", stdout);

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

	for (int i = 0; i < t; i++)
	{
		memset(best, 0, n * sizeof(int));
		for (int j = 0; j < n; j++)
		{
			scanf("%d%d%d", &cutie[j].x, &cutie[j].y, &cutie[j].z);
		}
		sort(cutie, cutie + n);
		
		for (int j = 1; j < n; j++)
		{
			for (int k = 0; k < j; k++)
			{
				if (intra(cutie[k], cutie[j]) && best[k] >= best[j])
				{
					best[j] = best[k] + 1;
				}
			}
		}

		int sol = 0;
		for (int j = 0; j < n; j++)
			if (sol < best[j])
				sol = best[j];
		
		printf("%d\n", sol + 1);
	}

	return 0;
}