algorithm - Break an Array of Integers into the Maximum Number of Subarrays with Exact Sums -
if have array of integers like...
{3,5,5,6,6,6,6,6,6,7,7,8,8,8,9,9,9}
i want create maximum number of subarrays add 40 each element being used once. repeat numbers fine long not repeats have been used.
it's easy finding maximum number of subarrays , finding subarrays of 40, problem finding subarrays provide 40 , doesn't prevent other subarrays of 40 being formed.
i need output of subsets formed.
it sounds similar partitioning problem.
is there name problem? have solution?
not efficient perhaps can following -- find multiples of 40 subset-sum problem can solved, starting largest multiple of 40 <= total sum , working down. once find subset sums multiple of 40, solve appropriate k-partition problem subset. example, if multiple of 40 120 solve (if possible) 3-partition problem of breaking 3 sets of equal size. note isn't enough identify single subset sums 120 before ruling out solution 120 -- have @ subsets sum 120 since 1 such subset might have solvable 3-partition problem while such subset doesn't.
Comments
Post a Comment