Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me Subsets of a set can be generated using a mask. A good description of the method is presented at http://compprog.wordpress.com/2007/10/10/generating-subsets/. The page

Please help me

image text in transcribed
Subsets of a set can be generated using a mask. A good description of the method is presented at http://compprog.wordpress.com/2007/10/10/generating-subsets/. The page also contains a link to the code in C (sub.c) We will use subset generation in order to solve the following problem. Given a set of integers S and a number N. find all nonempty subsets of S whose sum is N. For example, given the set S=(1, 2, -1, 3) and the number N=3, there are three subsets of S whose sum is 3. The subsets are {1, 2) (since 1+2 = 3), {1, -1, 3} (since 1+(-1)+3 = 3), and {3). Your program should do the following: 1) Prompt the user to enter the size of set S, elements of S, and the number N. Assume that the size of S is no more than 10. Store the elements of S in an array. 2) Generate all subsets of S using a mask. 3) For each nonempty subset generated in 2), compute the sum of elements in the subset. If the sum of elements in the subset is equal to N then output the subset. 4) Output total number of subsets of S that have the sum of elements equal to N. If none of the subsets of S have sum N, then output that they do not exist. Dialog with the user may look like the following: Please enter the size of S: 3 Please enter S: 5 2 3 Please enter the number N: 5 Subsets with sum 5: There are 2 subsets with sum 5. Another example of Dialog with the user: Please enter the size of S: 4 Please enter S: 10 20 30 40 Please enter the number N: 5 Subsets with sum 5: do not exist

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions