Line splitting algorithm
1 answer
One approach to this very problem is discussed in the book Introduction to Algorithms (Cormen, Leiserson, Rivest, Stein) as problem 15-2 .
A well-broken block of text is required to have as much spacing at the end as possible, penalizing large differences.
This problem is solvable with dynamic programming .
Naturally, this is only one approach to the problem, but in my opinion it at least looks better than the greedy algorithm.
I don't really want to invest my solutions in tutorials problems on the internet, so I'll leave it to the solution or google's solution to get the exact algorithm.
+1
source to share