Question: Please help on this C++ Program For this program you'll write a program that uses a recursive function to carry out a depth-first search. The
Please help on this C++ Program
For this program you'll write a program that uses a recursive function to carry out a depth-first search.
The Teddy Bear Game is played as follows:
You start the game with N teddy bears, 0 < N <= 10,000.
You may ask for or give back teddy bears according to these rules:
If the number of teddy bears you have is an even number, you can turn in (remove) exactly half the teddy bears you have.
If the number of teddy bears you have is a multiple of 3, you can ask for (receive) one third as many teddy bears as you currently have. (So if you have 33, you can ask for another 11.)
You can always ask for (receive) exactly 23 teddy bears.
There is no priority among the rules; you may choose any rule that applies in a given situation.
The number of teddy bears you hold must always be greater than 0 and can never be more than10,000.
The object of the game is to end with exactly 17 teddy bears in no more than 20 turns.
Your program will ask the user for the starting number of teddy bears, and then use a recursive function to search for a solution. Your program must use recursion to receive full credit. Output for each case is either a statement that no solution within 20 turns exists (determined after exhaustivesearch) or a listing of what choices are necessary to end with exactly 17. Because you'reusing a recursive function, it may be simpler to list it from the last step going backwards towards the beginning; that's fine.Allow the user to enter multiple values for N. If the user enters values out of range, prompt for reentry.Ask the user after each case whether to continue.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
