ps5sol

# ps5sol - Introduction to Algorithms Massachusetts Institute...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Handout 21: Problem Set 5 Solutions You have an input text consisting of a sequence of n words of lengths 1 , 2 , . . . , n , where the length of a word is the number of characters it contains. Your printer can only print with its built-in Courier 10-point fixed-width font set that allows a maximum of M characters per line. (Assume that i M for all i = 1 , . . . , n .) When printing words i and i + 1 on the same line, one space character (blank) must be printed between the two words. Thus, if words i through j are printed on a line, the number of extra space characters at the end of the line—that is, after word j —is M j + i j k . k = i To produce nice-looking output, the heuristic of setting the cost to the square of the number of extra space characters at the end of the line has empirically shown itself to be effective. To avoid the unnecessary penalty for extra spaces on the last line, however, the cost of the last line is 0 . In other words, the cost linecost ( i, j ) for printing words i through j on a line is given by if words i through
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern