Write a program that, given an integer number and integer numbers , prints all the subsets (maybe with repeated numbers, but using every at most once) whose sum is exactly .
Input consists of an integer number , followed by a number , followed by .
Print all the subsets whose sum is that can be made up with .
You can print in any order both the solutions and the elements inside each solution.
For this exercise, simple backtracking solutions are accepted. No optimizations are required.
Input
6 7 1 -2 0 3 -4 5 1
Output
{5,1}
{0,5,1}
{-2,3,5}
{-2,0,3,5}
{1,5}
{1,3,-4,5,1}
{1,0,5}
{1,0,3,-4,5,1}
Input
0 2 -5 5
Output
{}
{-5,5}