A general optimisation remark: to reduce the memory foot-print, one can immediately reject all arrays in which the "anchor"-element ("1" in the given example) is not contained. In the given example this already reduces the number of arrays to process by 25%.
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law