Given a rectangular grid where all the cells are initially white, you perform the following procedure K times:
- Select a cell from the grid at random, and call it A
- Select a cell from the grid at random, and call it B
- Color all the cells in the rectangle bounded by A and B
Each cell is selected at random, with uniform distribution, and each selection is independent from the other selections. It's possible that A and B correspond to the same cell.
For example, the image below shows a 5x7 grid where the selected pairs could have been (row, column):
- (0,1); (3,2)
- (3,6); (4,0)
- (0,6); (0,5)
Resulting in a grid with 22 colored cells and 13 white cells.
You are given ints rows and cols, the dimensions of the grid. Return the expected number of colored cells after K steps. |