Perhaps this will help if you look at the problem as follows:
In your example, you have a line like this:
AA BB C DDDD E FFF
Positions in space are places where you could start a new column. In any other place you should not store the same letters in one column. Thus, you can mark a position in space as follows:
AA1BB2C3DDDD4E5FFF
Now you have 5 positions where you can either split the column or not, since this is a binary solution, use the brute force row 0 and 1 for this:
12345 00000 -> no break at all, column count = 1, max. lines = 13 ... 01010 -> your example, column count = 3, max. lines = 5 ... 11111 -> breaks everywhere, column count = 6, max. lines = 4
This is a brute force attempt, but you can easily see that the number 1 affects the number of columns (number of columns = number 1 + 1), and you want to minimize the maximum. lines, it should be possible to somehow figure out without experiencing every combination.
EDIT2: didn't recognize that you need 3 columns, this makes it easier since you know that you only have 3 1, but that is still brute force.
EDIT: Another approach I would prefer:
Write a letter like this:
ABCDEF 2 2 1 4 1 3
Now you can join the letters that are next to each other. Always choose the two letters with the smallest invoice amount:
2 2 1 4 1 3 - lowest = "2 1" 2 3 4 1 3 - lowest = "1 3" 2 3 4 4 - lowest = "2 3" 5 4 4 - stop now, as we have 3 columns now Result: AABBC, DDDD, EFFF
This may not lead to an optimal solution, but it is a good and easy way to solve your problem, I think.