Given for example a square matrix of order n=4 as below: \begin{bmatrix} 1 & 0 & 1 & 0 \ 1 & 0 & 1 & 0 \ 0 & 1 & 0 & 0 \ 0 & 0 & 0 & 1 \end{bmatrix}
Trying all possible permutations of rows and columns is possibile to find three distinct diagonal block matrices as below: $ $ \begin{bmatrix} 1 & 0 & 0 & 0 \ 0 & 1 & 0 & 0 \ 0 & 0 & 1 & 1 \ 0 & 0 & 1 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \ 0 & 1 & 1 & 0 \ 0 & 1 & 1 & 0 \ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 1 & 0 & 0 \ 1 & 1 & 0 & 0 \ 0 & 0 & 1 & 0 \ 0 & 0 & 0 & 1 \end{bmatrix}$ $
I created a python script that allows me to do this. But the problem is the computation is too high because the number of permutations is $ $ n! * n!$ $ In fact, if we used for example a square matrix of order n=7, the number of all permutations would be $ $ 7! * 7!= 25.401.600$ $ So my question is: is there a way to reduce the number of permutations that always allows me to find all the diagonal block matrices or at least one of these?