1. One or more computer storage media having computer-readable instructions embodied thereon for performing a method of grouping electronic ink strokes into lines of handwritten text that utilizes a global cost function to calculate a cost of grouping strokes into lines, the method comprising the steps of: (a) receiving a plurality of electronic ink strokes; (b) partitioning the plurality of electronic ink strokes into an initial stroke grouping, the initial stroke grouping comprising an arrangement of one or more initial line groups of strokes, each of the one or more initial line groups of strokes comprising a line of handwritten text; (c) generating an alternate stroke grouping, the alternate stroke grouping comprising an alternate arrangement of one or more alternate line groups of strokes, each of the one or more alternate line groups of strokes comprising a line of handwritten text, wherein the alternate stroke grouping is a variation of the initial stroke grouping; (d) calculating, using a global cost function, a cost associated with the initial stroke grouping; (e) calculating, using the global cost function, a cost associated with the alternate stroke grouping; and (f) determining whether the cost associated with the alternate stroke grouping is less than the cost associated with the initial stroke grouping, wherein: (1) if the cost associated with the alternate stroke grouping is not less than the cost associated with the initial stroke grouping, the method further comprises outputting the initial stroke grouping to an application; and (2) if the cost associated with the alternate stroke grouping is less than the cost associated with the initial stroke grouping, the method further comprises repeating the steps of (c)-(f) wherein the alternate stroke grouping is substituted for the initial stroke grouping.