Computer Science, asked by mohdrafay7598, 1 year ago

Divide numbers in equal groups with closest sum c++

Answers

Answered by divyansh1125
0
So, more formally speaking, I'm getting N numbers and need to divide them into K groups that non of this groups are empty. The sum of ranges in each group need to be minimal. For example:

N = 4, K = 2 and the input is {5,3,1,1}.

One possible solution is {5,3},{1,1}. The sum of the ranges is 2 ((5-3)+(1-1)).

One more way to look at this is {1,1,3}{5} which is also 2 ((3-1)+(range of single number is 0)).

The range is always the difference between the biggest number in a group and the smallest number in the group.

When I searched the internet it was obvious that I need to use dynamic programming but all that I was come up with is solutions for K=2.
**********************************
Have a great day

Please mark this answer as Brainliest Answer

Similar questions
Math, 9 months ago