CSES - Shared codeLink to this code:
https://cses.fi/paste/c9b8bdf1ac11f0de582fcd/
class Solution:
def process(self, coins, target):
dp = [0 for _ in range(target + 1)]
dp[0] = 1
mod = 10**9+7
for val in range(target + 1):
for coin in coins:
if (val - coin) >= 0:
if dp[val - coin] > 0:
dp[val] += dp[val - coin]
if dp[val]>mod: dp[val]-= mod
else:
break
return dp[-1]
line = input()
n, target = list(map(lambda x: int(x.strip()), line.split()))
coins = list(map(lambda x: int(x) ,input().split()))
print(Solution().process(sorted(list(set(coins))), target))