Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在哪里可以找到一种有效的算法来打破文本行以进行格式化显示?
解决这个问题的一种方法在《算法简介》(Cormen、Leiserson、Rivest、Stein)一书中作为问题 15-2进行了讨论。
它采用一种方法,即一个很好的文本块在末尾有尽可能均匀的间距,惩罚大的差异。
这个问题可以使用动态规划来解决。
当然,这只是解决问题的一种方法,但在我看来,它至少看起来比贪心算法更好。
我不太愿意将教科书问题的解决方案放在互联网上,所以我将留给您解决它或谷歌寻求解决方案,以获得所需的确切算法。