Algorithm to split an array into P subarrays of balanced sum
问题 I have an big array of length N, let's say something like: 2 4 6 7 6 3 3 3 4 3 4 4 4 3 3 1 I need to split this array into P subarrays (in this example, P=4 would be reasonable), such that the sum of the elements in each subarray is as close as possible to sigma, being: sigma=(sum of all elements in original array)/P In this example, sigma=15 . For the sake of clarity, one possible result would be: 2 4 6 7 6 3 3 3 4 3 4 4 4 3 3 1 (sums: 12,19,14,15) I have written a very naive algorithm based