动态规划
cnt初始化为amonut+1,
cnt[j]=min(cnt[j],cnt[j-coins[i]]+1)
class Solution {
public:
int coinChange(vector<int>& coins, int amount) {
if(amount < 0) return -1;
vector<int> cnt(amount+1, amount+1);
cnt[0] = 0;
for(int i=0; i<coins.size(); ++i) {
for(int j=coins[i]; j<=amount; ++j) {
cnt[j] = min(cnt[j], cnt[j-coins[i]] + 1);
}
}
return (cnt[amount]==amount+1) ? -1 : cnt[amount];
}
};