Cod sursa(job #2332104)

Utilizator mihai50000Mihai-Cristian Popescu mihai50000 Data 30 ianuarie 2019 13:23:46
Problema Cutii Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <bits/stdc++.h>

using namespace std;

class InParser 
{

private:
	FILE *fin;
	char *buff;
	int sp;
	
	char read_ch() 
	{
		sp++;
		if(sp == 4096) 
		{
			sp = 0;
			fread(buff, 1, 4096, fin);
		}
		return buff[sp];
	}
	
public:
	
	InParser(const char* nume) 
	{
		fin = fopen(nume, "r");
		buff = new char[4096]();
		sp = 4095;
	}

	InParser& operator >> (int &n) 
	{
		char c;
	
		while(!isdigit(c = read_ch()));
			n = c - '0';
	
		while(isdigit(c = read_ch()))
			n = 10 * n + c - '0';
	
		return *this;
	}
};

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

bool cmp(Box a, Box b)
{
	return a.x < b.x;
}

const int DIM = 3507;

Box v[DIM];
int best[DIM];

int n, t, k, i, j, mx;

int main()
{
	InParser fin("cutii.in");
	freopen("cutii.out", "w", stdout);
	
	fin >> n >> t;
	
	for(k = 1; k <= t; k++)
	{
		for(i = 1; i <= n; i++)
		{
			fin >> v[i].x >> v[i].y >> v[i].z;
		}
		
		sort(v + 1, v + 1 + n, cmp);
		
		mx = 1;
		
		for(i = 1; i <= n; i++)
		{
			best[i] = 1;
			
			for(j = 1; j < i; j++)
				if(v[i].y > v[j].y && v[i].z > v[j].z && best[i] < best[j] + 1)
					best[i] = best[j] + 1;
					
			if(best[i] > mx)
				mx = best[i];
		}
		
		printf("%d\n",mx);
	}
}