Cod sursa(job #643159)

Utilizator d.andreiDiaconeasa Andrei d.andrei Data 3 decembrie 2011 01:46:04
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <cstdio>
#include <algorithm>

using namespace std;

#define file_in "cutii.in"
#define file_out "cutii.out"

#define nmax 5010

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

int N,T;
int i,maxx,j;
cutie v[nmax];
int best[nmax];

int cmp(cutie a, cutie b){
	return a.z<b.z;
}

#define D 8192
char g_buf[D];
int g_p=D-1;


inline int get()
{

	int x=0,neg;
	while ((g_buf[g_p]<'0' || g_buf[g_p]>'9'))
		if (++g_p==D) fread(g_buf,1,D,stdin),g_p=0;
	
	while (g_buf[g_p]>='0' && g_buf[g_p]<='9'){
		x=x*10+g_buf[g_p]-'0';
		if (++g_p==D) fread(g_buf,1,D,stdin),g_p=0;
	}
	return x;
}

int main(){
	
	freopen(file_in,"r",stdin);
	freopen(file_out,"w",stdout);
	
	N=get();
	T=get();
	while(T--){
		for (i=1;i<=N;++i)
			 v[i].x=get(),
			 v[i].y=get(),
			 v[i].z=get();
		sort(v+1,v+N+1,cmp);
		maxx=0;
		best[N]=1;
		for (i=N-1;i>=1;--i){
			best[i]=1;
			for (j=i+1;j<=N;++j)
				 if (best[i]<best[j]+1 && v[i].x<=v[j].x && v[i].y<=v[j].y && v[i].z<=v[j].z)
					  best[i]=best[j]+1;
		}
		for (i=1;i<=N;++i)    
			if (best[i]>maxx) maxx=best[i];
		printf("%d\n", maxx);
		
	}
	
	return 0;
}