Given an array of distinct integers A and a target value val, find all unique combinations of integers from A where their sum is equal to val.
Note: Each integer may be used multiple times in the combination.
A: [1, 2]
val: 4
Combinations: [
[1, 1, 1, 1],
[1, 1, 2],
[2, 2]
]
The first line contains an integer ‘T’, denoting the number of test cases.
For each test case the input has three lines.
For each test case, the output has the following lines:
3
2
1 2
4
5
1 3 4 5 6
4
5
1 2 3 4 8
7
3
1 1 1 1
1 1 2
2 2
3
1 1 1 1
1 3
4
11
1 1 1 1 1 1 1
1 1 1 1 1 2
1 1 1 1 3
1 1 1 2 2
1 1 1 4
1 1 2 3
1 2 2 2
1 2 4
1 3 3
2 2 3
3 4
1 <= T <= 10
1 <= n <= 30
1 <= target <= 500
1 <= Ai <= 500