Number of rectangles in a grid of size at least $W \times H$

196 Views Asked by At

The number of rectangles of all sizes in a grid is given by

$$\binom{m+1}{2}\binom{n+1}{2}$$

I want to how many rectangles can you select in a grid of $m \times n$ if you had restriction on the size of the rectangle to be atleast $W\times H$ where the

$$W \le \text{width of rectangle} \le m$$

$$H \le \text{height of rectangle} \le n$$

1

There are 1 best solutions below

1
On BEST ANSWER

For the $x$-coordinates, you are counting pairs $(a,b)$ with $0\le a<b\le m$ and $b-a\ge W$. This is the same as counting pairs $0\le a<c\le m-W+1$ where we let $c=b-W+1$. So there are $\binom{m+2-W}2$such pairs. The overall answer is $$\binom{m+2-W}2\binom{n+2-H}2.$$