#K12711. Combination Sum Finder
Combination Sum Finder
Combination Sum Finder
You are given a list of candidate integers and a target integer. Your task is to find all unique combinations of candidates where the chosen numbers sum to the target. Each candidate may be used unlimited times. All numbers (including the target) are positive integers.
Formally, given a sorted list \( A = [a_1, a_2, \dots, a_n] \) and a target \( T \), find all lists \( L \) such that
\[ \sum_{x \in L} x = T \]
Each combination must be output in non-decreasing order. If there is no valid combination, output an empty list.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains zero or more integers (space separated) representing the candidate numbers. If the line is empty, it means the candidate list is empty.
- The second line contains a single integer representing the target sum \( T \).
outputFormat
Output to standard output (stdout) in the following format:
- The first line prints an integer \( k \) representing the number of valid combinations found.
- The following \( k \) lines each contain one combination. In each line, print the numbers in the combination (in non-decreasing order) separated by a single space.
- If no combination exists, output only the number 0 on the first line.
2 3 6 7
7
2
2 2 3
7
</p>