Cod sursa(job #7593)

Utilizator damaDamaschin Mihai dama Data 21 ianuarie 2007 19:43:51
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <stdio.h>
#include <algorithm>
#include <string.h>

using namespace std;

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

bool cmp(cutie a, cutie b)
{
	return a.x < b.x;
}

int n, t, len[3501], sol;
cutie v[3501];

int main()
{
	freopen("cutii.in","r",stdin);
	freopen("cutii.out","w",stdout);
	
	int test, i, j;
	
	scanf("%d%d", &n, &t);
	
	for(test = 1; test <= t; ++test)
	{
		sol = 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);
		memset(len, 0, sizeof(len));
		for(i = n; i >= 1; --i)
		{
			for(j = i + 1; j <= n; ++j)
			{
				if(v[i].y < v[j].y && v[i].z < v[j].z && len[i] < len[j] + 1)
				{
					len[i] = len[j] + 1;
				}
			}
			if(len[i] == 0)
			{
				len[i] = 1;
			}
		}
		for(i = 1; i <= n; ++i)
		{
			if(sol < len[i])
			{
				sol = len[i];
			}
		}
		printf("%d\n",sol);
	}
	
	
	
	return 0;
}