combinations and permutations, how can I formulate it?

39 Views Asked by At

What mathematical formulation that can help me to generate all possible (N x N) matrices where the sum of all elements inside each matrix equal constant number M ? Note that: M > N If it can be solved using combinations and permutations, how can I formulate it ?

1

There are 1 best solutions below

1
On

If the positions of the matrix are distinct you are looking for weak compositions of $M$ into $N^2$ pieces. There are ${M+N^2-1 \choose N^2-1}$ of them. The Wikipedia article derives this.