题目
动态规划
代码语言:javascript复制class Solution {
public:
int dp[10005];
int coinChange(vector<int>& coins, int amount) {
memset(dp,-1,sizeof(dp));
dp[0] = 0;
for(int i=1;i<=amount;i )
{
for(int j=0;j<coins.size();j )
{
if(i-coins[j]>=0 && dp[i-coins[j]]!=-1)
{
if(dp[i]==-1)
dp[i] = dp[i-coins[j]] 1;
else
dp[i] = min(dp[i],dp[i-coins[j]] 1);
}
}
}
return dp[amount];
}
};