number of rectangles (including squares)

76 Views Asked by At

I have a grid of squares of unit length each with value 0 or 1. I want to count the number of squares or rectangles that can be made within this grid no taking the unit sqaures with value 1. If the number of cells having 0 is z and number of cells having 1 is one. Is there any relation between these two? Can I calculate my result with these numbers?

1

There are 1 best solutions below

0
On

You don't have enough information. If your grid is $3 \times 3$ and the $1$ cell is in the upper left corner there are nine squares (including one $2 \times 2$), five vertical $1 \times 2$ rectangles, two vertical $1 \times 3$ rectangles, and seven horizontal rectangles, for a total $23$. If the $1$ square is in the center there are eight squares, four vertical $2 \times 1$, two vertical $3 \times 1$ and six horizontal for a total $20$