A list contains the integers . How many ways can you choose numbers from the list so that their sum is ?
You may assume that and that . The algorithm should be efficient in all these cases.
In a file getsum.py
, implement a function count
that returns the desired count.
def count(n, k, x): # TODO if __name__ == "__main__": print(count(1, 1, 1)) # 1 print(count(5, 2, 6)) # 2 print(count(8, 3, 12)) # 6 print(count(10, 4, 20)) # 16
Explanation: When , and , the answer is . Here the list is and the possible ways are , , , , and .