Given a set of positive numbers and a number, your task is to find out the combinations of the numbers from the set whose summation equals to the given number
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Let there is a set S of positive numbers N and a positive number.
Making some combinations in such a way that the summation of that combination results that given number is a problem of combination and we will solve this problem using a backtracking approach.
Let, f(i) = function to insert the ith number into the combinational subset.
In this case, we will consider two cases to solve the problem,
And every time we will check the current sum with the number. Each of the time we will count the number of occurrence and the also the combinations.
Let, f(i) = function to insert the ith number into the combinational subset.
For the input:
Here in this case we will discard that edges which have a current sum greater than the given number and make a count to those numbers which are equal to the given number.
C++ implementation:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer