链接: http://www.lintcode.com/zh-cn/problem/coin-change-ii/#
给出不同面值的硬币以及总金额. 试写一函数来计算构成该总额的组合数量. 你可以假设每一种硬币你都有无限个.
class Solution {
public:
/**
* @param amount: a total amount of money amount
* @param coins: the denomination of each coin
* @return: the number of combinations that make up the amount
*/
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(int j=coins[i];j<=amount;j++)
{
dp[j]+=dp[j-coins[i]];
}
}
return dp[amount];
}
};