CSES - Choice of sum

A list contains the integers 1n1 \dots n. How many ways can you choose kk numbers from the list so that their sum is xx?

You may assume that 1n101 \le n \le 10 and that 1kn1 \le k \le n. 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 n=8n=8, k=3k=3 and x=12x=12, the answer is 66. Here the list is [1,2,3,4,5,6,7,8][1,2,3,4,5,6,7,8] and the possible ways are [1,3,8][1,3,8], [1,4,7][1,4,7], [1,5,6][1,5,6], [2,3,7][2,3,7], [2,4,6][2,4,6] and [3,4,5][3,4,5].