You own a sawmill business, which produces wooden boards. To simplify, we'll assume
that all boards have the same width and thickness: only their length differs.
Your only client gave you a buy list of various cuts (i.e. lengths):
for each length, they will buy any amount of board of that length that you can provide,
and pay you a given price for each board of that length. The per-length price varies.
Today, a tree trunk arrived in your factory, and you were able to produce one
very long board of length L (which you can then re-cut in smaller boards).
Your work is to determine how to cut this single board of length L in sellable
boards, so as to maximize your total sell price.
Implement in a new file cut.cc the function OptimalCut() described in file cut.h:
#ifndef __CUT_H
#define __CUT_H
#include <vector>
using namespace std;
// Describes a particular 'cut' of a wooden board: its length and price.
struct PricedCut {
int length; // Always >= 1.
double price; // Always > 0.
};
// Finds the optimal way to cut a board of length L into smaller, sellable
// cuts, so as to maximize the total sale price.
// Returns this maximum sale price.
// Also outputs the list of chosen cuts (a given cut may be repeated several
// times), in any order, in the vector "cut_indices": one will simply write
// the indices of the cuts from the original "cuts" vector.
//
// IMPORTANT: The unit test of this function has 2 parts: first, it tests
// the return value, then it tests the "cut_indices" output. If you don't
// fill the latter, you may still score points.
//
// WARNING: prices are doubles (i.e. floating-point numbers), not integers.
//
// EXAMPLE:
// OptimalCut(257, {{40, 3.8}, {70, 6.7}, {90, 9.0}}) = 6.7 + 9.0 + 9.0
// avec cut_indices = [1,2,2].
double OptimalCut(int L, const vector<PricedCut>& cuts,
vector<int>* cut_indices)
#endif // __CUT_H
Test: make cut
TO SUBMIT: cut.cc