Cod sursa(job #316718)

Utilizator pcinfoCarmen Popescu pcinfo Data 20 mai 2009 21:26:46
Problema Cutii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream f("cutii.in");
ofstream g("cutii.out");

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

struct compar
{
   bool operator()(cutie c1,cutie c2) { return (c1.x<c2.x && c1.y<c2.y && c1.z<c2.z); }
};


int main()
{
	
	cutie c;
	
	int n,nr,i,j;
	f>>n>>nr;
	
	vector<cutie> a(n);
	vector<int> t(n);
	int max;
	
	while (nr>0)
	{
		nr--;
		for (i=0;i<n;i++)
		{
			f>>c.x>>c.y>>c.z;
			a[i]=c;
		}
		
		sort(a.begin(), a.end(), compar());
		max=0;
		
		t[0]=1;
		for (i=1;i<n;i++)
		{
			t[i]=1;
			for (j=0;j<i;j++)
				if (a[j].x<a[i].x && a[j].y<a[i].y && a[j].z<a[i].z && t[j]+1>t[i])
					t[i]=t[j]+1;
			if (t[i]>max)
				max=t[i];
		}
		g<<max<<"\n";
	}
	
	g.close();
	return 0;	
}