insert (y - x) 0's to A at various places such that A*B is minimum. For instance, if A = (1, -1) and
B = (1,2, 3, 4), then inserting two 0's in the middle of A such that A = (1, 0, 0, -1) would minimize
A*B. I think he was looking for a dynamic problem solution.
--------------------------------------------------------------------------------------------------------------
Dynamic programming works, that is right.
Perhaps it is similar to Dr House's verbose solution, but the below is O(yx) (and not Omega(y^2x) which Dr House claims his solution is).
Sub problem:
Try to find the solution (Sol[i,j]) for A[1...i] and B[1...j] where 1 <= i <= x and 1 <= j <= y.
We get the recurrence relation:
Sol[i,j] = min {A[i]*B[j] + Sol[i-1, j-1], Sol[i, j-1]}
The first term corresponds to multiplying B[j] by A[j] and the second term corresponds to multiplying B[j] by 0.
Since the recurrence step is O(1), the complete algorithm is O(yx).

本文介绍了一种使用动态规划解决的问题:如何通过在较短数组中插入适当数量的零来最小化两个数组的乘积结果。算法的时间复杂度为O(yx),其中y和x分别是两个数组的长度。
1763

被折叠的 条评论
为什么被折叠?



