eolymp
bolt
Try our new interface for solving problems
Məsələlər

The King`s Ups and Downs

The King`s Ups and Downs

The king has guards of all different heights. Rather than line them up in increasing or decreasing height order, he wants to line them up so each guard is either shorter than the guards next to him or taller than the guards next to him (so the heights go up and down along the line). For example, seven guards of heights \textbf{160}, \textbf{162}, \textbf{164}, \textbf{166}, \textbf{168}, \textbf{170} and \textbf{172} cm. could be arranged as: \includegraphics{https://static.e-olymp.com/content/cf/cf2b46c28a1d4da3cb9c3ca7adf8fe0b6319ba2a.jpg} or perhaps: \includegraphics{https://static.e-olymp.com/content/0c/0c0e19313b58bf93b93265827cb5f1a32b5c92b5.jpg} The king wants to know how many guards he needs so he can have a different up and down order at each changing of the guard for rest of his reign. To be able to do this, he needs to know for a given number of guards, n, how many different up and down orders there are: For example, if there are four guards: \textbf{1}, \textbf{2}, \textbf{3}, \textbf{4} can be arranged as: \textbf{1324, 2143, 3142, 2314, 3412, 4231, 4132, 2413, 3241, 1423} For this problem, you will write a program that takes as input a positive integer \textbf{n}, the number of guards and returns the number of up and down orders for \textbf{n} guards of differing heights. \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 consists of single line of input containing two integers. The first integer, \textbf{D} is the data set number. The second integer, \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{20}), is the number of guards of differing heights. \OutputFile For each data set there is one line of output. It contains the data set number (\textbf{D}) followed by a single space, followed by the number of up and down orders for the \textbf{n} guards.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 32 MiB
Giriş verilənləri #1
4
1 1
2 3
3 4
4 20
Çıxış verilənləri #1
1 1
2 4
3 10
4 740742376475050