求多少种一般是动态规划 要具体写出各种的情况一般是dfs
本题类似于换硬币
class Solution:
def combinationSum4(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
dp=[0]*(target+1)
dp[0]=1
for i in range(1,target+1):
for n in nums:
if n<=i: dp[i]+=dp[i-n]
return dp[target]