Tables aren't inherently bad, there was a time when people went for tableless design using a subset of CSS, just to prove what could be done.
But here, you want the table to avoid the absolute positioning problem, if you use absolute positioning or relative even you end up removing elements from the document flow so you often have to rejig things.
The 50x50 grid idea by Dotty is the start point, the table is the simpler way of doing this (no absolute), and you can say with the 50x50 idea or you can further refine it and allow line breaks in the cells (but that is more challenging to extrapolate).
Well you have a number of stages to the overall problem:
The first is in selecting a number of images that will produce a rectangle of the dimensions you want.
So assume you have 15 x 15 of 50 x 50 cells, so 750 x 750.
The first image can be a maximum of 750 x 750 let's say it is 500 x 700, the next image can be 250 x 750 and let's say it is 250 x 100.
That is the top row done. But you now have a jagged line below to fill, and it becomes harder to find a filling piece towards the end.
So, you might want a few 50s in there, but that will tend to make the last few 50s
Once you have the pieces that make up a rectangle, then filling the grid on 50 x 50 is a simple division by 50 of the dimensions and applying that to colspan and rowspans.
But for extra marks you can also reduce the number of cells to a minimum so if you find for example all are even colspans of 2 or more, then you could divide by 2, and line breaks could be used to reduce the number of rows, though this is more advanced and therefore you could introduce an error quite easily.
It is the first bit that is hardest, and some of it could help in the last bit if you want to go the extra mile.