Combination Sum

MediumRecursion & Backtracking
Next
BacktrackingRecursion

Given distinct positive integers (candidates) and a target, find every unique combination of candidates that adds up to the target. A candidate may be used any number of times. Print each combination in ascending order on its own line, with the combinations in lexicographic order, or None if there are none.

Input

Line 1: n and the target. Line 2: n distinct positive integers.

Output

One combination per line (numbers ascending), combinations in lexicographic order, or None.

Constraints

1 <= n <= 8 2 <= each candidate <= 40 1 <= target <= 40

Example 1
Input
4 7
2 3 6 7
Output
2 2 3
7

2+2+3 = 7 and 7 = 7.

Hints

Combination Sum - Medium Recursion & Backtracking Problem | Skill Shiksha