Given a list of integers, write a program to print the count of all possible unique combinations of numbers whose sum is equal to k.
Input:
The first line of Input will contain space-separated Integer.
The second line of Input will contain an 8nteger,denoting K.
Sample Input:
2 4 6 1 3
Output:
3
from itertools import combinations
listOfInt = [int(i) for i in input().split()]
k = int(input())
cnt = 0
for i in range(1,len(listOfInt)+1):
for tmp in combinations(listOfInt, i):
if sum(tmp) == k:
cnt += 1
print(cnt)
Comments
Leave a comment