将一个数组划分为两个子数组,每个子数组具有最大和,并等于其他数组和

时间:2018-06-20 18:00:01

标签: arrays algorithm data-structures dynamic-programming subset-sum

给定一个整数数组,我们如何将其划分为两个子集,以使一个数组中的元素之和等于另一个数组中的元素之和,并且该和为最大?我们可以随意从给定的数组中选择一个数字。

eg.
Given array: [2, 3, 4, 1, 6] 
Possible subsets with equal sum:
 a. [2, 3] and [4, 1] where sum = 5
 b. [2, 6] and [3, 4, 1] where sum = 8
 c. [2, 3, 1] and [6] where sum = 6 and we didn't include 4 in subsets

Here b is the expected subset.

另外,1 <= arr [i] <= 1000

最大数组长度为1000

0 个答案:

没有答案