Knuth's The Art of Computer Programming, Volume 4, Fascicle 2: Generating all Tuples and Permutations gives efficient (non-recursive) solutions to this and many other combinatorial enumeration problems.
Section 7.2.1.2 contains 36 pages of material devoted to precisely the question you ask.
No comments:
Post a Comment