Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. Consider the problem of word-wrapping a paragraph of text. A paragraph is an ordered list of n words, where word w; is li letters
2. Consider the problem of word-wrapping a paragraph of text. A paragraph is an ordered list of n words, where word w; is li letters long. You want to divide the paragraph into a sequence of lines, each containing at most L letters. (No word is more than L letters long.) Suppose a line contains words Wi ... W;. The total length W(i, j) of this line is defined by W(i,j) =j-i + lako k=i This length accounts for a single space between successive pair of words on the line. The slop Sli,j) of this line is defined to be L - W(i,j), the total number of unused spaces at the end of the line. Note that in any feasible solution, the slop of each line must be non-negative. Just to make things concrete, consider the example paragraph Now is the time for all good men.", and suppose L = 10. One feasible solution is Now is the time for all good men. This solution has four lines of lengths 10, 8, 8, and 4; the corresponding slops are 0, 2, 2, and 6. Your goal is to find a division of the input paragraph into lines that minimizes the sum, over all lines except the last, of the squared slop of each line. (We omit the last line because it can in general be much shorter than the others.) For example, the total cost of the above solution is 02 +22 + 22 = 8. Give a polynomial-time algorithm for this
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started