Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- struct Milk
- {
- double fillingTime;
- double packingTime;
- Milk(const double& fillingTime,
- const double& packingTime):
- fillingTime(fillingTime),
- packingTime(packingTime)
- {
- }
- };
- size_t attempt = 1;
- using milk_t = Milk;
- bool isCombined(const vector<size_t>& combo, const size_t& id)
- {
- for (const auto& it : combo)
- {
- if (it == id)
- {
- return true;
- }
- }
- return false;
- }
- void funcMethod(const vector<milk_t>& milks,
- vector<size_t>& currentCombo,
- vector<size_t>& bestCombo,
- double& currentTime,
- double*& bestTime,
- const double& packingTimeBefore
- )
- {
- if (currentCombo.size() == milks.size())
- {
- if (bestTime == nullptr || currentTime <= *bestTime)
- {
- bestTime = new double(currentTime - packingTimeBefore);
- bestCombo = currentCombo;
- cout << endl << attempt++ << ": New best time" << endl;
- }
- else
- {
- cout << endl << attempt++ << ": Nothing interesting" << endl;
- }
- for (const auto& it : currentCombo)
- {
- cout << it << " ";
- }
- cout << endl << "CurrentTime: " << currentTime << " ; BestTime: " << *bestTime << endl;
- return;
- }
- for (size_t it = 0; it < milks.size(); it++)
- {
- if (!isCombined(currentCombo, it))
- {
- const milk_t tempMilk = milks[it];
- double addition = 0;
- if (tempMilk.fillingTime > packingTimeBefore)
- {
- addition = tempMilk.fillingTime - packingTimeBefore;
- }
- addition += tempMilk.packingTime;
- currentTime += addition;
- currentCombo.push_back(it);
- funcMethod(milks, currentCombo, bestCombo, currentTime, bestTime, tempMilk.packingTime);
- currentCombo.pop_back();
- currentTime -= addition;
- }
- }
- }
- void func(const vector<milk_t>& milks)
- {
- double currentTime = 0;
- double* bestTime = nullptr;
- vector<size_t> currentCombo, bestCombo;
- funcMethod(milks, currentCombo, bestCombo, currentTime, bestTime, 0);
- }
- int main()
- {
- const vector<milk_t> milks = {
- milk_t(5, 10),
- milk_t(6, 4),
- milk_t(8, 5),
- milk_t(22, 15),
- milk_t(3, 3)
- };
- func(milks);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement