I'm looking for an algorithm (preferably not a heuristic algorithm) that outputs a table layout with the least possible amount of rows given a fixed number of columns. The contents of the cells are grouped and a group may not split across multiple columns. Furthermore, groups within a column are separated by empty cells (no empty cells at the top and bottom of a column are required). The order of groups is fixed. Consider the following example:

Input: A1,A2,A3,B1,B2,C1,C2
Desired amount of columns is 2.
Output: Column 1 = A1,A2,A3,empty,empty; Column2 = B1,B2,empty,C1,C2
The number of rows in this table is 5.

Note that another possible layout (group B below group A) would give a table of 6 rows and is therefore not optimal. I wonder if this problem can be mapped onto an existing well known problem (and solution).