断行算法
在哪里可以找到一种有效的算法来断行文本以进行格式化显示?
Where can I find an efficient algorithm for breaking lines of text for formatted display?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
在哪里可以找到一种有效的算法来断行文本以进行格式化显示?
Where can I find an efficient algorithm for breaking lines of text for formatted display?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
算法简介(Cormen、Leiserson、Rivest、Stein)一书中解决了这个问题的一种方法: 问题 15-2。
它采用的方法是,一个完美的文本块在末尾具有尽可能均匀的间距,从而惩罚大的差异。
这个问题可以使用动态编程来解决。
当然,这只是解决问题的一种方法,但在我看来,它至少看起来比贪心算法更好。
我不太愿意把我的教科书问题的解决方案放在互联网上,所以我将把它留给你来解决它或谷歌寻找解决方案,以获得所需的确切算法。
One approach to this very problem is addressed in the book Introduction to Algorithms (Cormen, Leiserson, Rivest, Stein) as problem 15-2.
It takes the approach that a nicely broken block of text has as even spacing at the end as possible, punishing large differences.
This problem is solvable using 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'm not much for putting my solutions to textbook problems on the Internet, so I'll leave it to you to either solve it or Google for a solution, in order to get the exact algorithm needed.