Cod sursa(job #565425)

Utilizator pykhNeagoe Alexandru pykh Data 27 martie 2011 19:15:28
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include<cstdio>
#include<algorithm>
using namespace std;

const char in[]="cutii.in";
const char out[]="cutii.out";

const int Max_N = 3505;

int N, T, a[Max_N];

struct cutie{ int x, y, z; } v[Max_N];

struct cmp{
	bool operator()(const cutie &a,const cutie &b)
	{
		return a.x < b.x;
	}
};

inline int maxim(int a, int b){	return (a > b) ? a : b ; }
		
int main()
	{
		freopen(in,"r",stdin);
		freopen(out,"w",stdout);
		scanf("%d%d", &N, &T);
		
		while(T--)
		{
			int sol = 0;
			for(int 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());
			a[1]=1;
			for(int i = 2 ; i <= N ; ++i)
			{
				a[i] = 1;
				for(int j = i - 1 ; j >= 1 ; --j)
					if(v[i].x > v[j].x && v[i].y > v[j].y && v[i].z > v[j].z && a[j] + 1 > a[i])
						a[i] = a[j] + 1;
					sol = maxim(a[i], sol);
			}
			printf("%d\n", sol);
			for(int i = 1 ; i <= N ; ++i)a[i] = 0;
		}
		return 0;
}