An automated cutting machine is used to cut rods into segments. The cutting machine can…
- User
An automated cutting machine is used to cut rods into segments. The cutting machine can only hold a rod of minLength or more. A rod is marked with the necessary cuts and their lengths are given as an array in the order they are marked. Determine if it is possible to plan the cuts so the last cut is from a rod at least minLength units long. Example lengths = [4, 3, 2] minLength = 7 The rod is initially sum(lengths) = 4 +3 +2 = 9 units long. First cut off the segment of length 4 7 leaving a rod 9-7=2. Then check that the length 7 rod can be cut into segments of lengths 4 and 3. Since 7 is greater than or equal to minLength = 7, the final cut can be made. Return "Possible". Example lengths = [4, 2, 3] minLength = 7 The rod is initially sum(lengths) =4 +2 +3= 9 units long. In this case, the initial cut can be of length 40r 4 +2 = 6. Regardless of the length of the first cut, the remaining piece will be shorter than minLength. Because n - 1 = 2 cuts cannot be made, the answer is " Impossible. " Function Description Complete the function cutThemAll: cutThemAll has the following parameter(s): int lengths[n]: the lengths of the segments, in order. int minLength: the minimum length the machine can accept Returns string: "Possible" if all n-1 cuts can be made. Otherwise, return the string "Impossible".
boiler plate code: string cutThemAII (vector < long> lengths, long minLength) { }
Write C++ code for the problem
- Assistant
Here is the C++ code for the
cutThemAllfunction:cpp