Preallocating Array in a Memory Efficient Way

K is around 15! Yes, most elements will be 0. However, most of this are 3-dimensional arrays and I could not get sparse structures to work in this case. A MWE of my problem can be found here Performance Tips for Combinatorial Problem