我无法理解包合并算法。谁能一步一步解释包合并算法?我们如何打包以及如何合并?有没有其他最佳算法可以解决硬币收集器的问题?
我找到了一个算法Package-Merge
Algorithm(I, X) {
S is empty;
for all d, Ld list of items having width 2^d;
while X > 0 loop
minwidth = the smallest term in diadic expansion of X;
if I=0 then //is empty
return “No solution.” ;
else
d=the minimum such that L is not empty;
r=2^d;
if r > minwidth then
return “No solution.”
else if r = minwidth then
Delete the minimum weight ;
X= X - minwidth ;
end if
Pd+1=PACKAGE(Ld) ; …Run Code Online (Sandbox Code Playgroud) algorithm ×2