#C12433. Unique Combination Sum
Unique Combination Sum
Unique Combination Sum
You are given a list of positive integers and a target integer \(T\). Your task is to find all unique combinations in the list where the numbers sum to \(T\). Each number in the list may only be used once in each combination.
Note:
- The combinations must be output in non-decreasing order.
- Two combinations are considered unique if they differ in at least one element.
If there is no valid combination, output []
(without quotes).
inputFormat
The input consists of two lines:
- The first line contains several space-separated positive integers representing the list of numbers.
- The second line contains a single integer, the target sum \(T\).
outputFormat
For each unique combination that sums to \(T\), print a line with the numbers in that combination separated by a single space. The combinations should be printed in lexicographical order. If no valid combination exists, output []
(without quotes).
10 1 2 7 6 1 5
8
1 1 6
1 2 5
1 7
2 6
</p>