the aim is to obtain a particular
number using a subset of given values and four arithmetic operations. Note that you are allowed to use each
given value at most once. For example, suppose that you are given the following set of values {3, 6, 12,
24, 43} and you are asked to obtain 344. Using a subset of these values, 344 could be obtained after the
following operations ( 24 / 3 ) * 43. Here also note that the operations ( ( 24 / 12 ) + 6 ) * 43 can also be
used to obtain the same value.
In this question, you are going to write a C++ program that reads a subset of values as well as the
number that is to be obtained from the user and determines whether or not the number can be obtained by
using a subset of the given values and four arithmetic operations. If it is obtained, you should display the
operation sequence. Otherwise, you should display a message. Note that, unlike the contest, your program
will allow the user to enter a set of values with different sizes.
Think about solving this question by iteration. You will notice that it is much more difficult to write its
iterative solution compared to the recursive one.
Some sample outputs of the program are given below:
Enter the number of values: 5
Enter 5 values: 3 8 9 25 50
Enter the number: 564
( ( ( 9 + 25 ) * 50 ) - 8 ) / 3
Enter the number of values: 4
Enter 4 values: 2 7 17 48
Enter the number: 745
No result
Enter the number of values: 6
Enter 6 values: 3 7 9 12 27 62
Enter the number: 684
( ( ( 3 * 7 ) + 9 ) + 27 ) * 12
Enter the number of values: 4
Enter 4 values: 3 2 4 17
Enter the number: 18
( ( 3 + 2 ) - 4 ) + 17
Enter the number of values: 3
Enter 3 values: 3 2 4
Enter the number: 16
No result
Enter the number of values: 3
Enter 3 values: 4 7 13
Enter the number: 21
No result
Enter the number of values: 6
Enter 6 values: 12 87 7 2 9 15
Enter the number: 1023
( ( ( ( 87 - 7 ) - 2 ) - 9 ) * 15 ) - 12
2
Enter the number of values: 4
Enter 4 values: 4 12 34 78
Enter the number: 34
34
In your program:
• You can assume that only integers are given as the input.
• Remember that a value in a set could be used at most once.
• A number could be found in different sequence of operations; remember how we found 344 at the
beginning. Your program could output one of these correct sequences.