Cod sursa(job #417965)

Utilizator s_holmesSherlock Holmes s_holmes Data 15 martie 2010 11:16:37
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <cstdio>
#include <algorithm>
#define NMAX 3501
using namespace std;
int N, T;
struct coord
{
	int x, y, z;	
}C[NMAX];

void citire()
{
	for(int i = 1 ; i <= N ; i++)
		scanf("%d%d%d",&C[i].x, &C[i].y, &C[i].z);
}

bool comp(coord a, coord b)
{
	return a.x < b.x;
}

int dinamic()
{
	int maxim = 1;
	int d[NMAX] = {0};
	for(int i = 1 ; i <= N ; i++)
	{
		d[i] = 1;
		for(int j = 1 ; j < i ; j++)
			if(C[j].y < C[i].y && C[j].z < C[i].z && d[j] + 1 > d[i])
				d[i] = d[j] + 1;
		if(d[i] > maxim)
			maxim = d[i];
	}
	
	return maxim;
}

int main()
{
	freopen("cutii.in","r",stdin);
	freopen("cutii.out","w",stdout);
	scanf("%d%d",&N, &T);
	for(int k = 1 ; k <= T ; k++)
	{
		citire();
		sort(C + 1, C + N + 1,comp);
		printf("%d\n",dinamic());
	}
	return 0;
}