I'm trying to solve a variant of the partition problem. I have two important twists. I need to solve for k partitions, not just 2, as in the classic partition problem.
The following code does that:
https://gist.github.com/ishikawa/21680
I also need to allow the freedom to jumble up the order of the items, so that I can get the optimal solution. So, where the classic problem requires the order of the elements be left in tact, and the array is just split at an semi-optimal points, I need to allow the array to be re-ordered in such a way as the difference between the partitions is smallest.
How can I tackle this? Both twists are necessary for this real world application. I'd be extremely happy if I could find a Java library that already handles this.