两个子集之和最小差异

编程入门 行业动态 更新时间:2024-10-26 08:24:32
本文介绍了两个子集之和最小差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

伙计们,

遇到了一个问题......发现这个野趣......我改变一点点只是涂PEP起来。

  

给定一组整数(范围0-500)的,发现了可以通过将它们几乎同样地形成两个子集之和之间的最小差异。 (比如说整数计数是n,当n为偶数,每一组必须具有n / 2个元件,如果n是奇数,一组具有第(n-1)/ 2个元素和其他具有第(n + 1)/ 2个元素)

     

采样开关输入:1 2 3 4 5 6

     

最小差异= 1(亚群是1 4 6和2 3 5)

     

样品输入2:[1 1 1 1 2 2 2 2]

     

最小差异= 0(子集是1 1 2 2 1 1 2 2)

有DP方法这个问题。

感谢球员...

拉​​吉...

解决方案

这个问题看起来几乎像平衡分区。

您可以使用一个DP的方法来建立一个伪多项式时间算法,解决了平衡的分区。参见问题7在people.csail.mit.edu/bdean/6.046/dp/

这听起来像你可以有一个类似的方法。

Folks,

came across a problem... found this intersting... am modifying it a little bit just tu pep it up.

Given a set of integers (range 0-500), find the minimum difference between the sum of two subsets that can be formed by splitting them almost equally. (say count of integers is n, if n is even, each set must have n/2 elements and if n is odd, one set has (n-1)/2 elements and other has (n+1)/2 elements)

sample imput : 1 2 3 4 5 6

minimal difference = 1 (subsets being 1 4 6 and 2 3 5 )

sample input 2 : [ 1 1 1 1 2 2 2 2 ]

minimal difference = 0 (subsets being 1 1 2 2 and 1 1 2 2 )

is there DP approach for this problem.

Thanks guys...

raj...

解决方案

This problem looks almost like the "balanced partition".

You can use a DP approach to build a pseudo-polynomial time algorithm that solves the balanced partition. See problem 7 at people.csail.mit.edu/bdean/6.046/dp/

It sounds like you could have a similar approach.

更多推荐

两个子集之和最小差异

本文发布于:2023-11-29 00:13:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644520.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子集   之和   最小   差异   两个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!