213. Combination Sum
MediumBacktracking
Using the distinct positive candidates (each usable any number of times), print every combination that sums to the target. Each combination is printed in non-decreasing order; combinations are printed in lexicographic order. Print NONE if there are none.
Input format
Line 1: n target Line 2: n distinct positive integers
Output format
One combination per line, or NONE.
Example 1
Input
4 7 2 3 6 7
Output
2 2 3 7
Example 2
Input
3 8 2 3 5
Output
2 2 2 2 2 3 3 3 5
Constraints
1 ≤ n ≤ 10 1 ≤ target ≤ 40
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…