Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Office 365 For Beginners 2022 8 In 1

Authors: James Holler

1st Edition

B0B2WRC1RX, 979-8833565759

Students also viewed these Databases questions