Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a C++ program -Do not Use any kind of loop, you can/have-to use recursion- for (thanks in advance): Task F. Fair division Alice and
Write a C++ program -Do not Use any kind of loop, you can/have-to use recursion- for (thanks in advance):
Task F. Fair division 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[-110, 15, 12, 18, 19, 17, 13, 35, 33)i 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+1917 + 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 smoller 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 18 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) Otherwise, there is no solutionStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started