Permutations
Hints
(Try not to use 'em, you won't get 'em during the contest.)
The set of permutations of a sequence of integers is the set of all
possible sequences made of the same integers shuffled. If the
integers are distinct, then there are n! (n factorial) elements in the
set of permutations.
We can order these permutations in a simple fashion: For two sequences
s1 and s2 if the nth element of s1 and
s1 is the first that differs, then s1 is < s2
if and only if s1[n] < s2[n] (essentially
lexicographic ordering).
Write a program that reads in an integer k, followed by a
series of no more than 10 integers (read until EOF) and prints out the
kth permutation in of that series, with a single space between
each pair of integers, and a newline at the end. If k is
greater than the size of the set of permutations, print out "Not
enough permutations."
Test Files
permute-1.in
permute-1.out
permute-2.in
permute-2.out
permute-3.in
permute-3.out