Question: c++ program, use recursion! Alice and Bob inherited a collection of paintings. However, they will receive it only if the collection can be divided into


c++ program, use recursion!
Alice and Bob inherited a collection of paintings. However, they will receive it only if the collection can be divided into two parts of exactly equal price. (Otherwise, it will be donated to a local art museum.) Is the collection divisible into two exactly equal halves? We have to find the answer. The prices of the paintings are provided as an array of integers. For example: int prices [ (10, 15, 12, 18, 19, 17, 13, 35, 33) Here, the total sum is 172, so each person should receive the sum of 86. In this specific example,a solution exists, it is the following partition: (1015 12 19 17 13) (18 35 33) 86. How to solve the problem recursively? Consider the example above. Is it possible to divide [10, 15, 12, 18, 19, 17, 13, 35, 33] into sums of 86 and 86? Each item should go either to Alice or to Bob. Let's take the first item, 10. Should we give it to Bob or Alice? In either case, there can be a solution. So, let's try both options The problem instance we want to solve Solvable([10, 15, 12, 18, 19, 17, 13, 35, 33]. Alice gets 86, Bob gets 86) Its solution requires solving two slightly smaller subproblems YES if Alice gets 10 and Solvable([15, 12, 18, 19, 17, 13, 35, 33], Alice gets 76, Bob gets 86) YES if Bob gets 10 and Solvable([15, 12, 18, 19, 17, 13, 35, 33 Alice gets 86, Bob gets 76) NO otherwise If we can give 10 to Alice, and the rest can be divided so that she gets 76 and Bob gets 86, then a solution exists (and Alice gets 10) Also, if we can give 10 to Bob and the rest can be divided so that he gets 76 and Alice gets 86, then the solution also exists (and Bob gets 10)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
