Given a collection of integers and threshold value T, divide the collection into as many groups as possible whose sum >= T

安稳与你 提交于 2020-05-12 07:56:07

问题


Given a collection of integers and threshold value T, divide the collection into as many groups as possible whose sum >= T.

The remaining integers (whose sum < T, so another group cannot be formed) should be left outside of the groups.

Constraints:

  • length of the list <= 1,000
  • values and T <= 1,000,000

Is there an algorithm for this problem in polynomial time?

For example given [25,25,25,50,50,50,10] and a threshold T = 70 it should return:

[25,50]
[25,50]
[25,50]
Remaining: [10]

Selecting [25,25,25] as one of the groups would make it possible to only form one more group, [50,50] and the remaining values would be [50,10]. Two groups are not the optimal amount of groups, which is why this solution would be incorrect.


回答1:


There is no polynomial time algorithm for this since it contains as a special case the np-complete Partition problem.



来源:https://stackoverflow.com/questions/61306597/given-a-collection-of-integers-and-threshold-value-t-divide-the-collection-into

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