Horizontal side of rectangle formed must be <= K
example: if N = 3 and K = 2 ans = 30
example: if N = 2 and K = 1 ans = 6
How to derive generalized formula?
Horizontal side of rectangle formed must be <= K
example: if N = 3 and K = 2 ans = 30
example: if N = 2 and K = 1 ans = 6
How to derive generalized formula?
Copyright © 2021 JogjaFile Inc.
HINT: A rectangle is determined by its four sides. There is no restriction on the height, so the top and bottom edges can be any two of the $N+1$ horizontal lines of the grid. Thus, there are $\binom{N+1}2$ ways to choose the top and bottom edges of the rectangle. Now we have to count the number of pairs of vertical grid lines that are at most $K$ units apart. If you draw some sketches, you should be able to see that for $1\le w\le K$ there are $N-w+1$ pairs of vertical grid lines $w$ units apart.
Thus, there are
$$\sum_{w=1}^K(N-w+1)=\sum_{w=1}^K(N+1)-\sum_{w=1}^Kw=K(N+1)-\sum_{w=1}^Kw$$
ways to choose the vertical edges of the rectangle. To complete the calculation, express $\sum_{w=1}^Kw$ in a closed form as a function of $K$, and then suitably combine the number of possibilities for the horizontal edges of the rectangle with the number of possibilities for the vertical edges.