小红书秋招 python

题1


image.png

动态规划问题

str = list(input().split())
total = int(str[0])
prices = list(map(int, str[1].lstrip('[').rstrip(']').split(',')))
arr = [0] * (total + 1)
arr[0] = 1
for price in prices:
    for i in range(total - price + 1):
        if arr[i]:
            arr[i + price] += arr[i]
print(arr[total])

你可能感兴趣的:(小红书秋招 python)