Fill a 5×5 grid!

There is a 5×5 grid in front of you. You have to fill 25 squares with only 0 and 1.

But, every neighboring square's (that is not diagonally adjacent) number's product has to be 0.

How many possible grids there are?


The answer is 55447.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Mark Hennings
Jan 4, 2019

Each row can be filled in one of 13 13 different ways, each way representing one of the binary numbers in S = { 0 , 1 , 2 , 4 , 8 , 16 , 5 , 9 , 10 , 17 , 18 , 20 , 21 } S = \{0, 1, 2, 4, 8, 16, 5, 9, 10, 17, 18, 20, 21\} .

If a particular row is represented by the number x S x \in S , then then next row can be represented by the number y S y \in S provided that the bitwise AND x & y x \mathrm{\&} y of x x and y y is 0 0 . Thus we can obtain the recursive formulae X 0 ( x ) = 1 X m ( x ) = y S , x & y = 0 X m 1 ( y ) x S , m 1 \begin{aligned} X_0(x) & = \; 1 \\ X_m(x) & = \; \sum_{y \in S,x \mathrm{\&} y = 0}X_{m-1}(y) \end{aligned} \hspace{3cm} x \in S\,,\, m \ge 1 where X m ( x ) X_m(x) is the number of ways in which an ( m + 1 ) × 5 (m+1) \times 5 array can be filled with no adjacent 1 1 s, given that the first row is represented by the number x S x \in S . It is a simple matter to calculate that X 5 ( 0 ) = 55447 X_5(0) \; = \; \boxed{55447}


Another way of seeing this result is to note that the first, third and fifth rows can be chosen freely from S S . If the first, third and fifth rows are x , y , z S x,y,z \in S respectively, then the second row could be any u S u \in S such that u & x = u & y = 0 u \mathrm{\&} x = u \mathrm{\&} y = 0 , and hence such that u & ( x y ) = 0 u \mathrm{\&} (x|y) = 0 , where x y x|y is the bitwise OR of x x and y y . If we define N ( x , y ) = { u S u & ( x y ) = 0 } x , y S N(x,y) \; = \; \left| \big\{ u \in S \,\big| \, u \mathrm{\&} (x|y) = 0\big\} \right| \hspace{2cm} x,y \in S then the desired number of grid numberings is x , y , z S N ( x , y ) N ( y , z ) = y S ( x S N ( x , y ) ) 2 = 55447 \sum_{x,y,z \in S} N(x,y)N(y,z) \; = \; \sum_{y \in S} \left(\sum_{x \in S} N(x,y)\right)^2 \; = \; 55447

in the first solution can you give details how you used the recursive relation to compute X5(0). i am getting stuck. honestly i thought it is an impossible to solve this using elementary techniques. i thought a computer code is the only option. it is nice solution.

Srikanth Tupurani - 2 years, 4 months ago

thanks i got it. nice solution.

Srikanth Tupurani - 2 years, 4 months ago

in the second solution can you explain the last step.

Srikanth Tupurani - 2 years, 4 months ago

From a combinatorial perspective, when one views filling the grid with ones and zeros, one can treat it as summation of (5,k) as k approaches 5. This yields 2^5=32 . This is a stark contrast to your 13. Could you please account for the discrepancy? Thanks.

Aravind Narayanan - 2 years ago

Log in to reply

Remember, we cannot have two adjacent squares both containing 1 1 , so while there are 2 5 = 32 2^5=32 ways of filling a row with 0 0 s and 1 1 s, corresponding to all integers from 0 0 to 31 31 , we are not allowed numbers whose binary expansion contains consecutive 1 1 s. Thus the number 19 = 1001 1 2 19 = 10011_2 is not allowed. There are only 13 13 numbers between 0 0 and 31 31 whose binary expression does not contain successive 1 1 s; they are 0 0 (no 1 1 s), 1 , 2 , 4 , 8 , 16 1,2,4,8,16 (one 1 1 ), 5 , 9 , 10 , 17 , 18 , 20 5,9,10,17,18,20 (two 1 1 s) and 21 21 (three 1 1 s).

Mark Hennings - 2 years ago
Kim Eric
Jan 4, 2019

This is an example of a 5 × 5 5×5 grid:

You can make a C - programme to solve this problem. (If you run the programme and type "5 5" and wait for just a few seconds, you can get the answer.)

Try it!!!

The phrasing of the problem is extremely unclear, even misleading. I suggest Mark Henning's re-phrasing.

Jon Haussmann - 2 years, 5 months ago
K T
Jul 21, 2019

The condition is equivalent to stating that no two ones can be adjacent. Focusing on rows, there are 13 different rows possible: A=00000, B=00001, C=00010, D=00100, E=00101, F=01000, G=01001, H=01010, I=10000, J=10001, K=10010, L=10100, M=10101.

Two rows can occur directly above each other if they have no ones in common (for the programmers: a bitwise logical AND should result in 0).

Pattern A can have all 13 neighbours (ABCDEFGHIJKLM) directly below or above it, B can have 8 (ACDFHIKL), C can have 10 (ABDEFGIJLM), D can have 9 (ABCFGHIJK), E can have 6 (ACFHIK), F can have  10 (ABCDEIJKLM), G can have 6 (ACDIKL), H can have 8 (ABDEIJLM), I can have 8 (ABCDEFGH), J can have 5 (ACDFH), K can have 6 (ABDEFG), L can have 6 (ABCFGH), M can have 4 (ACFH).

We start filling the grid by choosing a pattern for the middle row

  • suppose it is an A-pattern. above that row, we can have any row, suppose that row is a C then it can have 10 neigbours. It can be any of the others too, so A in  the middle gives 13+10+...+4=99 ways to put 2 rows above it and also 99 ways to put two rows below it 9 9 2 99^2 .
  • suppose it is a B-pattern. Next to row B we can have A,C,D,F,... so certain neighbours are excluded. The rows total up to 13+10+9+10...=70 ways, for the top rows, so 7 0 2 70^2 ways
  • proceeding this way we get 9 9 2 + 7 0 2 + 7 5 2 + 7 4 2 + 5 5 2 + 7 5 2 + 5 2 2 + 5 9 2 + 7 0 2 + 5 0 2 + 5 2 2 + 5 5 2 + 4 1 2 = 55447 99^2+70^2+75^2+74^2+55^2+75^2+52^2+59^2+70^2+50^2 +52^2+55^2+41^2=\boxed{55447} ways.

1 pending report

Vote up reports you agree with

×

Problem Loading...

Note Loading...

Set Loading...