Cod sursa(job #1768285)

Utilizator preda.andreiPreda Andrei preda.andrei Data 30 septembrie 2016 17:07:33
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <algorithm>
#include <fstream>
#include <tuple>
#include <vector>

using namespace std;

typedef tuple<int, int, int> Cutie;

bool ComparaCutii(const Cutie &a, const Cutie &b)
{
	return get<0>(a) > get<0>(b);
}

bool Incape(Cutie &mare, Cutie &mic)
{
	return get<0>(mare) > get<0>(mic) && get<1>(mare) > get<1>(mic) && get<2>(mare) > get<2>(mic);
}

int main()
{
	ifstream fin("cutii.in");
	ofstream fout("cutii.out");

	int n, t;
	fin >> n >> t;

	vector<Cutie> cutii(n + 1);
	vector<int> turn(n + 1, 0);

	while (t--) {
		for (int i = 1; i <= n; ++i)
			fin >> get<0>(cutii[i]) >> get<1>(cutii[i]) >> get<2>(cutii[i]);
		sort(cutii.begin() + 1, cutii.end(), ComparaCutii);

		int raspuns = 0;
		for (int i = 1; i <= n; ++i) {
			turn[i] = 1;
			for (int j = i - 1; j >= 1; --j) {
				if (turn[j] + 1 > turn[i] && Incape(cutii[j], cutii[i]))
					turn[i] = turn[j] + 1;
			}
			raspuns = max(raspuns, turn[i]);
		}

		fout << raspuns << "\n";

		if (t > 0) {
			for (int i = 1; i <= n; ++i)
				turn[i] = 0;
		}
	}

	return 0;
}