My issue
Traceback (most recent call last):
File “/mnt/sol.py”, line 31, in
main()
File “/mnt/sol.py”, line 20, in main
T = int(input())
^^^^^^^
EOFError: EOF when reading a line
My code
# cook your dish here
def find_combinations(arr, target):
def backtrack(start, path, target):
if target == 0:
result.append(path[:])
return
for i in range(start, len(arr)):
if arr[i] > target:
break
path.append(arr[i])
backtrack(i, path, target - arr[i])
path.pop()
arr.sort()
result = []
backtrack(0, [], target)
return result
def main():
T = int(input())
for _ in range(T):
N, B = map(int, input().split())
arr = list(map(int, input().split()))
combinations = find_combinations(arr, B)
print(len(combinations))
for combination in combinations:
print(" ".join(map(str, combination)))
if __name__ == "__main__":
main()
Learning course: Design and Analysis of Algorithms
Problem Link: https://www.codechef.com/learn/course/kl-daa/KLDAA2400I/problems/RECUR23