First of all, sorry if this is a simple question. I am programmer and facing a problem about calculation.
I have rectangle surface ($x_{s}$) with height $h_{s}$ and width $w_{s}$ and I want to put $n$ rectangles ($x_{n}$) with same height $h_{n}$ and width $w_{n}$ in the surface like a grid. $x_{n}$ can scale up or down but they must keep the aspect ratio. The problem is how can I get the maximize the area $x_{n}$? I need to calculate scaled $h_{n'}$ and $w_{n'}$, and how many column and row will be used?
Here is an example picture
