Pagini recente » Cod sursa (job #1387226) | Cod sursa (job #2960717) | Cod sursa (job #366041) | Cod sursa (job #2126991) | Cod sursa (job #1267980)
#include <vector>
#include <algorithm>
#include <fstream>
#include <cassert>
void TestSorting();
void RunTests();
struct Box
{
int width;
int length;
int height;
};
std::vector<Box> Boxes;
int MaxChainForBox[4000];
int MaxChainOverall;
bool CompareBoxesByHeight(const Box& boxA, const Box& boxB)
{
return boxA.height > boxB.height;
}
bool BoxFitsIn(const Box& boxA, const Box& boxB)
{
return (boxA.length < boxB.length) && (boxA.width < boxB.height) && (boxA.height < boxB.height);
}
int GetMaxChainForBox(int boxIndex, int endIndex)
{
std::vector<int> chains;
for (int i = boxIndex + 1; i < endIndex; ++i)
{
if (BoxFitsIn(Boxes[i], Boxes[boxIndex]))
{
chains.push_back(1 + GetMaxChainForBox(i, endIndex));
}
}
if (chains.size() > 0)
{
return *std::max_element(chains.begin(), chains.end());
}
return 1;
}
int main()
{
int tests = 0;
int boxCount = 0;
std::ifstream inFile("cutii.in");
std::ofstream outFile("cutii.out");
inFile >> boxCount;
inFile >> tests;
for (int i = 0; i < tests; ++i)
{
Boxes.clear();
MaxChainOverall = 0;
for (int j = 0; j < boxCount; ++j)
{
Box box;
inFile >> box.length;
inFile >> box.width;
inFile >> box.height;
Boxes.push_back(box);
}
std::sort(Boxes.begin(), Boxes.end(), &CompareBoxesByHeight);
MaxChainOverall = GetMaxChainForBox(0, (int)Boxes.size());
outFile << MaxChainOverall << std::endl;
}
outFile.close();
inFile.close();
return 0;
}