排列问题target背包在循环外面,组合问题target背包在里面。这是经典的求排列问题,凑零钱是组合问题

class Solution:
    def combinationSum4(self, nums: List[int], target: int) -> int:
        dp = [0]*(target+1)
        dp[0] = 1
        for i in range(1,target+1):
            for j in nums:
                if i>=j:
                    dp[i] += dp[i-j]
        return dp[-1]

377. Combination Sum IV刷题笔记_组合问题