#K14386. Combination Sum

    ID: 24123 Type: Default 1000ms 256MiB

Combination Sum

Combination Sum

Given an array of distinct integers and a target integer \(T\), find all unique combinations in the array where the candidate numbers sum to \(T\). Each number may be used an unlimited number of times. The solution set must not contain duplicate combinations.

For example, if the candidates are [2, 3, 6, 7] and \(T=7\), the valid combinations are \([2,2,3]\) and \([7]\). Note that the candidates array is not guaranteed to be sorted, so you may need to sort it beforehand.

inputFormat

Input Format:

  • The first line contains an integer \(n\), the number of candidates.
  • The second line contains \(n\) space-separated integers representing the candidate numbers.
  • The third line contains the target integer \(T\).

outputFormat

Output Format:

  • If there exists one or more valid combinations, print each combination in a separate line. In each line, print the numbers in non-decreasing order separated by a single space.
  • If no combination exists, print a single line containing [].
## sample
4
2 3 6 7
7
2 2 3

7

</p>