faster algorithms for minimum maximum contiguous k partition

别说谁变了你拦得住时间么 提交于 2019-12-23 02:18:44

问题


I was reading this http://www.cas.mcmaster.ca/~terlaky/4-6TD3/slides/DP/DP.pdf and would like to know if there exists a solution with better time complexity to the partition problem.

From the link:

"Suppose a given arrangement S of non-negative numbers {s1,...,sn} and an integer k. How to cut S into k or fewer ranges, so as to minimize the maximum sum over all the ranges?"

e.g.

S = 1,2,3,4,5,6,7,8,9

k=3

By cutting S into these 3 ranges, the sum of the maximum range (8,9) is 17, which is the minimum possible.

1,2,3,4,5|6,7|8,9

The algorithm suggested in the link runs in O(kn^2) and uses O(kn) space. Are there more efficient algorithms?


回答1:


Ok so apparently this was closed for being "off-topic"!? But it's back up now so anyway, I found the solution to be binary searching the answer. Sorry I forgot one of the constraints was that the sum of all the integers would not exceed 2^64. So let C = cumulative sum of all integers. Then we can binary search for the answer using a

bool isPossible(int x)

function which returns true if it is possible to divide S into k partitions with maximum partition sum less than X. isPossible(int x) can be done in O(n) (by adding everything from left to right and if it exceeds x make a new partition). So the total running time is O(n*log(s)).



来源:https://stackoverflow.com/questions/14659543/faster-algorithms-for-minimum-maximum-contiguous-k-partition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!