Maths Help - Calculate for a Grid

Entire books are written on this - the keyword to search for is rectangle packing.