混乱棒切割算法 - 动态规划算法、混乱、动态

2023-09-11 23:12:38 作者:没收星星

我最近看到一棒切割的问题,其中B(I)=价格最优的切削长度长我单位的杆我单位和P(I)=价格的一棒。

I recently saw a rod cutting problem, where B(i) = optimal price for cutting a rod of length i units and p(i) = price of a rod of length i units.

给出的算法是这样的: 乙(ⅰ)=最大(1&其中; = K&其中; =ⅰ){对(k)的+ B(Ⅰ-k)的}

The algorithm given is something like this: B(i) = max(1<=k<=i) {p(k) + B(i-k)}

难道不应该是这样的: B(I)= MAX(1&LT; = K&LT; =地板(I / 2)){B(K)+ B(IK)} 其中B(1)= P(1);

Shouldn't it be something like this: B(i) = max(1<=k<=floor(i/2)) {B(k) + B(i-k)} where B(1) = p(1);

让两个部分的'VE的最佳的成本,而不是成本的一​​个组成部分,最优性价比的第二部分单杆。

so that both parts 've the optimal cost instead of cost for a single rod for one part and optimal cost for the second part.

for example: B(4) = max{ (B(1) + B(3)); (B(2) + B(2)) }

instead of max{ (p(1) + B(3)); (p(2) + B(2)); (p(3) + B(1)) }

有人可以解释一下吗?

Can someone please explain this?

推荐答案

其实公式是正确的。你有B(I)= MAX(1&LT; = K&LT; = 1){p(k)的+ B(IK)}。让我们假设你有长度的绳子。如果你削减它,那么你将切下一块长度 K 其中K是在 1 和我键,将继续削减绳子的剩余部分。所以,总体来说它的成本你P(K)(价格下调,你决定了你将不会削减了初始部分),价格下调,其余 B(IK)。这是precisely什么公式呢。

Actually the formula is correct. You have B(i) = max(1<=k<=i) {p(k) + B(i-k)}. Let's assume you have a rope of length i. If you are to cut it then you will cut a piece of length k where k is between 1 and i and will go on cutting the remaining part of the rope. So overall it costs you p(k)(price to cut the initial part that you decided you will not cut anymore) and the price to cut the remaining B(i-k). This is precisely what the formula does.

您的解决方案也将做的工作,但它有一个小缺点 - 每个子问题的解决取决于(而不是一个)两个子问题简单的解决方案。我相信,因为这将平均表现较差。当然,有一个子问题取决于几个简单的问题并不被禁止或错误。

Your solution will also do the job but it has a slight drawback - the solution for each subproblem depends on the solution of two(instead of one) simpler subproblems. I believe because of that it will perform worse on the average. Of course having a subproblem depend on several simpler problems is not forbidden or wrong.

 
精彩推荐
图片推荐