378 Recursive Strategies I am the only child of parents who weighed, measured, and priced everything; for whom what could not be weighed, measured, and priced had no existence 6. -Charles Dickens, Little Dorrit, 1857 In Dickenss time, merchants measured many commodities using weights and a two-pan balance -a practice that continues in many parts of the world today If you are using a limited set of weights, however, you can measure only certain quantities. For example, suppose that you have only two weights: a 1-ounce weight and a 3-ounce weight. With these weights you can easily measure out 4 ounces, as shown: It is somewhat more interesting to discover that you can also measure out 2 ounces by shifting the 1-ounce weight to the other side, as follows: Write a recursive function bool isMeasurable (int target, Vector<int> &weights) that determines whether it is possible to measure out the desired target amount with a given set of weights, which is stored in the vector weights For example, suppose that sampleWeights has been initialized like this: Vector<int> sampleWeights; sampleweights += 1, 3; Given these values, the function call isMeasurable (2, sampleWeights) should return true because it is possible to measure out 2 ounces using the sample weight set as illustrated in the preceding diagram. On the other hand,

Solve the problem given in Exercise 8.6. Using a recursivealgorithm.

You must use recursion. Your code CANNOT use any loops (for,while, etc) to cycle through the weights except to calculate sumsor to print to the screen.

In addition to just a boolean of can it be balanced, also outputthe positioning of the masses to achieve balance. the test codewill call this function:

/*  
   calculate the positions of the weights such thatbalance can be achieved
   (if possible)

   if it is not possible to balance, return false and setleft, right
     to empty
   if it is possible, return true and set left, right tothe
     arrangement resulting in balance
  
   NOTE: there may be more than one solution, as long asyours
     balances, it will pass the test.
  
   fill left with the weights necessary to place tothe
      left of center (along with thetarget)
   fill right with the weights necessary to place to theright of center

   balance => left + target == right
*/

bool findBalance(int target, const std::vector &weights, std::vector &left, std::vector &right);378 Recursive Strategies I am the only child of parents who weighed, measured, and priced everything; for whom what could not be weighed, measured, and priced had no existence 6. -Charles Dickens, Little Dorrit, 1857 In Dickens’s time, merchants measured many commodities using weights and a two-pan balance -a practice that continues in many parts of the world today If you are using a limited set of weights, however, you can measure only certain quantities. For example, suppose that you have only two weights: a 1-ounce weight and a 3-ounce weight. With these weights you can easily measure out 4 ounces, as shown: It is somewhat more interesting to discover that you can also measure out 2 ounces by shifting the 1-ounce weight to the other side, as follows: Write a recursive function bool isMeasurable (int target, Vector &weights) that determines whether it is possible to measure out the desired target amount with a given set of weights, which is stored in the vector weights For example, suppose that sampleWeights has been initialized like this: Vector sampleWeights; sampleweights += 1, 3; Given these values, the function call isMeasurable (2, sampleWeights) should return true because it is possible to measure out 2 ounces using the sample weight set as illustrated in the preceding diagram. On the other hand, Show transcribed image text 378 Recursive Strategies I am the only child of parents who weighed, measured, and priced everything; for whom what could not be weighed, measured, and priced had no existence 6. -Charles Dickens, Little Dorrit, 1857 In Dickens’s time, merchants measured many commodities using weights and a two-pan balance -a practice that continues in many parts of the world today If you are using a limited set of weights, however, you can measure only certain quantities. For example, suppose that you have only two weights: a 1-ounce weight and a 3-ounce weight. With these weights you can easily measure out 4 ounces, as shown: It is somewhat more interesting to discover that you can also measure out 2 ounces by shifting the 1-ounce weight to the other side, as follows: Write a recursive function bool isMeasurable (int target, Vector &weights) that determines whether it is possible to measure out the desired target amount with a given set of weights, which is stored in the vector weights For example, suppose that sampleWeights has been initialized like this: Vector sampleWeights; sampleweights += 1, 3; Given these values, the function call isMeasurable (2, sampleWeights) should return true because it is possible to measure out 2 ounces using the sample weight set as illustrated in the preceding diagram. On the other hand,