% the program gives the k-subsets with repetitions of {1,...,p}, % everyone only once, %in lexicographic order function X=multisubsets(p,k) M=ones(1,k); for i=2:p M=[M, i*ones(1,k)]; end X=unique(nchoosek(M,k),'rows');