title: Can we solve the "printing neatly" problem using a greedy algorithm rather than dynamic programming?
body: <p>The "printing neatly" problem in the "introductions to algorithms" book is solved via dynamic programming. It's Problem 5.3 and the solution is found <a href="https://segue.middlebury.edu/repository/viewfile/polyphony-repository___repository_id/edu.middlebury.segue.sites_repository/polyphony-repository___asset_id/5299281/polyphony-repository___record_id/5299282/polyphony-repository___file_name/PrintingNeatly.pdf" rel="nofollow">here</a></p>
  
  <p>I think this problem could be simply solved by a greedy algorithm. Just put as many words per line as possible intil you can't fit the next word and so move to a new line.</p>
  
  <p>Can someone help me understand if this solution is enough ? (the greedy algo)</p>
  
  <p>Here's the problem: Printing neatly</p>
  
  <p>Consider the problem of neatly printing a paragraph on a printer. The input text is a sequence of n words of lengths l1,l2,...,ln, measured in characters. We want to print this paragraph neatly on a number of lines that hold a maximum of M characters each. Our criterion of "neatness" is as follows. If a given line contains words i through j and we leave exactly one space between words, the number of extra space characters at the end of the line is the difference between M and the total number of characters in the words plus the spaces between them  .We wish to minimize the sum, over all lines except the last, of the cubes of the numbers of extra space characters at the ends of lines. Give a dynamic-programming algorithm to print a paragraph of n words neatly on a printer. Analyze the running time and space requirements of your algorithm.</p>