Leetcode|完全背包|518. 零钱兑换 II

2021-09-18 16:40:51 浏览数 (1)

1 动态规划(完全背包)

代码语言:javascript复制
class Solution {
public:
    int change(int amount, vector<int>& coins) {
        vector<int> dp(amount   1, 0);
        dp[0] = 1;
        for (int i = 0; i < coins.size(); i  )
            // 完全背包:背包容量for循环升序
            for (int j = coins[i]; j <= amount; j  )
                dp[j] = dp[j]   dp[j - coins[i]];
        return dp[amount];
    }
};

0 人点赞