Cod sursa(job #643158)

Utilizator d.andreiDiaconeasa Andrei d.andrei Data 3 decembrie 2011 01:43:34
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 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;
}

int main(){
	
	freopen(file_in,"r",stdin);
	freopen(file_out,"w",stdout);
	
	scanf("%d %d", &N,&T);
	while(T--){
		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);
		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;
}