% the program gives the k-subsets with repetitions of {1,...,p} % with all possible orders function X=orderedmultisubsets(p,k) Y=multisubsets(p,k); X=zeros(0,k); for i=1:size(Y,1) X=[X;perms(Y(i,:))]; end X=unique(X,'rows');