Cod sursa(job #613692)

Utilizator NikitaUtiuNichita Utiu NikitaUtiu Data 4 octombrie 2011 14:15:57
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct struct_cutie {
	int a, b, c;
};

vector <int> vect_max;
vector <struct_cutie> vect_cutii;

int getMax(void);
inline bool compare(struct_cutie, struct_cutie);
inline bool fits(struct_cutie, struct_cutie);

int main(void) {
	int n, m;
	ifstream fin("cutii.in");
	
	fin >> n >> m;
	vect_cutii.resize(n);
	vect_max.resize(n);
	
	ofstream fout("cutii.out");
	for(int i = 0; i < m; ++i) {
		for(int j = 0; j < n; ++j) 
			fin >> vect_cutii[j].a >> vect_cutii[j].b >> vect_cutii[j].c;
		fout << getMax() << '\n';
	}
	fin.close();
	fout.close();
}

inline bool compare(struct_cutie a, struct_cutie b) {
	if(a.a < b.a) return true;
	if(a.a == b.a && a.b < b.b) return true;
	if(a.a == b.a && a.b == b.b && a.c < b.c) return true;
	return false;
}

inline bool fits(struct_cutie a, struct_cutie b) {
	return a.a < b.a && a.b < b.b && a.c < b.c;
}

int getMax(void) {
	int m = 1;
	sort(vect_cutii.begin(), vect_cutii.end(), compare);
	vect_max.assign(vect_max.size(), 1);
	
	for(int i = 1; i < vect_max.size(); ++i)
		for(int j = i - 1; j >= 0; --j) 
			if(fits(vect_cutii[j], vect_cutii[i]) && vect_max[i] < vect_max[j] + 1) {
				vect_max[i] = vect_max[j] + 1;
				m = max(m, vect_max[i]);
			}
	return m;
}