看起来用零钱兑换2的思路,两个for换一下位置就行了吧(我没考这题) class Solution: def change(self, amount: int, coins: List[int]) -> int: dp = [0] * (amount + 1) dp[0] = 1 for x in range(amount + 1): # 和原题相比两个for换了位置 for i in coins: if x >= i: dp[x] += dp[x - i] return dp[-1] coin就是牌,amount是血量 输入3 [1,2,2] 输出5(代码里要加个mod)