I need to write a program, which shows the different combinations in which matrices can be multiplied.

The output should look like below :

When there are two matrices multiplied there is one combination

(XX)

When there are three matrices multiplied there are two combinations

(X(XX)) ((XX)X)

When there are four matrices multiplied there are five combinations

(X(X(XX))) ((X(XX))X) (X((XX)X)) (((XX)X)X) ((XX)(XX))

Can someone please help me with its logic?

Thank you,