377. Combination Sum IV

202401312237
tags: #dp

from functools import lru_cache
	class Solution:
		def combinationSum4(self, nums: List[int], target: int) -> int:
			@lru_cache(maxsize=None)
			def solve(t):
				if t == 0:
					return 1
				res = 0
				for num in nums:
					if t >= num:
						res += solve(t - num)
				return res
			return solve(target)

Reference

https://leetcode.com/problems/combination-sum-iv/