Cod sursa(job #365312)

Utilizator AndreiDDiaconeasa Andrei AndreiD Data 18 noiembrie 2009 13:33:03
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;


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

int N,T,i,j,best[10000],v[10100],cmax;
struct cutie
{
	int x,y,z;
}
c[3501];

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", &c[i].x, &c[i].y, &c[i].z);
		}
		
		sort(c+1,c+N+1,cmp);
		
		cmax=0;
		
		memset(best,0,sizeof(best));
		
		best[N]=1;
		
		for (i=N-1;i>=1;--i)
		{
			best[i]=1;
			
			for (j=i+1;j<=N;++j)
				if (c[i].x<c[j].x && c[i].y<c[j].y && best[i]<best[j]+1)
					best[i]=best[j]+1;
			if (best[i]>cmax)
                cmax=best[i];
        }
		
		printf("%d\n", cmax);
	}
	
	fclose(stdin);
	fclose(stdout);
	
	return 0;
	
}