Cod sursa(job #1267980)

Utilizator PatrunjeluMarginean Bogdan Alexandru Patrunjelu Data 20 noiembrie 2014 15:39:34
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.68 kb
#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;
}