Pagini recente » Cod sursa (job #648719) | Cod sursa (job #328346) | Cod sursa (job #2307003) | Cod sursa (job #1677865) | Cod sursa (job #1268162)
#include <vector>
#include <algorithm>
#include <fstream>
#include <cassert>
const int MaxBoxes = 4000;
struct Box
{
int width;
int length;
int height;
};
std::vector<Box> Boxes;
int Lengths[MaxBoxes];
bool CompareBoxesByHeight(const Box& boxA, const Box& boxB)
{
return boxA.height < boxB.height;
}
int main()
{
int tests = 0;
int boxCount = 0;
std::ifstream inFile("cutii.in");
std::ofstream outFile("cutii.out");
inFile >> boxCount;
inFile >> tests;
for (int n = 0; n < tests; ++n)
{
Boxes.clear();
std::fill(Lengths, Lengths + MaxBoxes, 0);
for (int m = 0; m < boxCount; ++m)
{
Box box;
inFile >> box.length;
inFile >> box.width;
inFile >> box.height;
Boxes.push_back(box);
}
std::sort(Boxes.begin(), Boxes.end(), &CompareBoxesByHeight);
for (int i = boxCount - 1; i >= 0; --i)
{
for (int j = i + 1; j < boxCount; ++j)
{
if ((Boxes[i].width < Boxes[j].width) && (Boxes[i].length < Boxes[j].length) && (Lengths[i] < Lengths[j] + 1))
{
Lengths[i] = Lengths[j] + 1;
}
}
if (Lengths[i] == 0)
{
Lengths[i] = 1;
}
}
outFile << *std::max_element(Lengths, Lengths + MaxBoxes) << std::endl;
}
outFile.close();
inFile.close();
return 0;
}