{1,3,5}面额硬币;总和= 11 找到可用于制造总和 (我们可以使用任意数量的每种面值的硬币)硬币变化分析
我搜索了运行时该硬币找零问题的复杂硬币的最低数量特别是使用动态规划方法。但无法在任何地方找到解释。
如何计算非动态解决方案的复杂性,然后将其更改为动态解决方案? (不是贪婪之一)
编辑:
这里是其分析要求的实现。
public int findCoinChange(int[] coins, int sum,int count) {
int ret = 0, maxRet = -1;
if(sum ==0)maxRet = count;
else if(sum < 0)maxRet = -1;
else{
for(int i:coins){
ret = findCoinChange(coins, sum - i,count+1);
if(maxRet< 0)maxRet = ret;
else if(ret >=0 && ret < maxRet){
maxRet = ret;
}
}
}
if(maxRet < 0)return -1;
else return maxRet;
}
看起来像组合爆炸给我。不过,我不确定如何为此推导运行时复杂性。
相关:http://stackoverflow.com/questions/1986828/coin-changing-algorithm – jason
我认为贪婪将无法解决此问题。 – thefourtheye
thefourtheye - 贪婪并不总是给出最好的解决方案,例如Sum = 9; {1,4,5}贪婪会给 - {5,1,1,1,1}最优是{4,4} –