标签:and change 表示 ++ logs www. min size http
https://www.cnblogs.com/grandyang/p/5138186.html
用动态规划的方法, dp[i]表示当前金额最少换零钱的次数
class Solution { public: int coinChange(vector<int>& coins, int amount) { vector<int> dp(amount+1,amount+1); dp[0] = 0; for(int i = 1;i <= amount;i++){ for(int j = 0;j < coins.size();j++){ if(i >= coins[j]) dp[i] = min(dp[i],dp[i - coins[j]] + 1); } } return dp[amount] > amount ? -1 : dp[amount]; } };
标签:and change 表示 ++ logs www. min size http
原文地址:https://www.cnblogs.com/ymjyqsx/p/10486359.html