How to divide a line of numbers into N groups such that the sums of each group are closest to their mean using dynamic programming?
Fortunately you can calculate the group average that you are aiming for (sum of numbers, divided by the number of groups). In your case, you want the groups close to 18 1/3. 

So using dynamic programming, you solve "How do I split the first m numbers into n groups, minimizing abs (sum of numbers in group - 18 1/3)", for 0 ≤ m ≤ M, and for 1 ≤ n ≤ N. You solve this by putting 0 ≤ k ≤ m items in the last group, calculating the penalty for the last group and adding the solution for n-1 groups made from the first m-k items, picking the best choice.

It feels a bit weird, because the solutions you find on the way are awfully bad. Splitting the first 0 numbers for example into 3 groups creates 3 empty groups, with a total sum of 3 * (18 1/3) = 55, but it works. What you find for N groups from M numbers is optimal. 

This works easily on O (M^2 N). You can do this faster by first finding a reasonably good solution, and then excluding everything that isn't as good as the best solution. 

Example: First, make each group as large as possible without the first n groups exceeding n * 18 1/3, that is (1 2 3 4 5) (6 7 8) (9 10) with penalties 3 1/3, 2 2/3, 2/3, total 6 2/3. Now we only care for 1 group with a penalty ≤ 6 2/3, then for 2 groups with a penalty ≤ 6 2/3 etc. 

But also, if the remaining M-m items that need to go into N-n groups have a sum of S, they must have a penalty of at least abs (S - 18 2/3 * (N - n)), so the penalty for the first n groups plus this extra penalty must be ≤ 6 2/3. This will help if you have thousands of items.