eolymp
bolt
Try our new interface for solving problems
Problems

Maximum in the Cycle of 1

Maximum in the Cycle of 1

If \textbf{P} is a permutation of the integers \textbf{1}, ..., \textbf{n}, the maximum in the cycle of \textbf{1} is the maximum of the values \textbf{P(1)}, \textbf{P(P(1))}, \textbf{P(P(P(1)))}, etc. For example, if \textbf{P} is the permutation: \textbf{|1 2 3 4 5 6 7 8|} \textbf{|3 2 5 4 1 7 8 6|} we have: \textbf{P(1) = 3} \textbf{P(P(1)) = P(3) = 5} and \textbf{P(P(P(1))) = P(5) = 1} so the maximum in the cycle of \textbf{1} is 5. For this problem, you will write a program which takes as input integers \textbf{n} (\textbf{n} > \textbf{0}) and \textbf{k} (\textbf{1} ≤ \textbf{k} ≤ \textbf{n}), and returns the number of permutations of the integers \textbf{1}, ..., \textbf{n}, for which the maximum in the cycle of \textbf{1} is \textbf{k}. \InputFile The first line of input contains a single integer \textbf{P} (\textbf{1} ≤ \textbf{P} ≤ \textbf{1000}), which is the number of data sets that follow. Each data set is a single line that contains the three space separated decimal integer values. The first value is the data set number \textbf{N}. The second value is the size of the permutation, n where (\textbf{1} ≤ \textbf{n} ≤ \textbf{20}), and the third value is the desired maximum in the cycle of \textbf{1}, \textbf{k} where (\textbf{1} ≤ \textbf{k} ≤ \textbf{n}). \OutputFile For each data set there is one line of output. It contains the data set number \textbf{N} followed by a single space, followed by a double precision floating point whole value which is the number of permutations of the integers \textbf{1}, ..., \textbf{n}, for which the maximum in the cycle of \textbf{1} is \textbf{k}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
4
1 4 1
2 7 3
3 10 5
4 20 7
Output example #1
1 6
2 168
3 86400
4 11585247657984000
Source 2011 Greater New York Regional