(1)dp,完全平方数类似
class Solution {
public:
int coinChange(vector<int>& coins, int amount) {
int maxs=amount+1;
int n=coins.size();
vector<int> v(amount+1,maxs);
v[0]=0;
for(int i=1;i<amount+1;i++) {
for(int j=0;j<n;j++) {
if(i>=coins[j])
v[i]=min(v[i],v[i-coins[j]]+1);
}
}
return v[amount]==maxs?-1:v[amount];
}
};