Question
Consider an equal group problem: given n positive integers, partition them into two disjoint groups with the same sum of their elements. Of course, the
Consider an equal group problem: given n positive integers, partition them into two disjoint groups with the same sum of their elements. Of course, the problem does not always have a solution. In the homework, you should write a C++ program called equal_group.cpp to solve the problem. In the program, you can assume that the max number of input integer values is 15. And also, you can assume that the input values are all distinct. This is a sample run of the program $ g++ -o equal_group equal_group.cpp $ ./equal_group Number of input: 4 Enter 4 numbers: 1 2 3 4 Equal Group: 1 4 vs 2 3 Done. This is another sample run: $ g++ -o equal_group equal_group.cpp $ ./equal_group Number of input: 3 Enter 3 numbers: 1 5 7 Equal Group: Not exist Done. When you display the solution, the output sequence is not important. In other words, the following can be the answer to the first sample execution: Equal Group: 1 4 vs 2 3 or Equal Group: 1 4 vs 3 2 or Equal Group: 3 2 vs 4 1 ... For the problem, if more than one partition is available, you only need to display one case. [Hint]: To solve this problem, you can consider all possible subsets for the input numbers. For this, you can use the binary representation from 0 to 2n 1 for the number of input numbers n.
Step 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