Running Steps
InterviewTime limit1sMemory limit256 MB
Count left-right alternating sequences of one-step and two-step strides where both legs use equal counts and twos are at least as many as ones.
- Level
Medium5 of 10
- Topics
- Combinatorics, Math
- Solved
- No attempts yet
Problem
A coach wants his runners to climb the stadium steps one or two steps at a time, under four rules.
- Each leg takes the same number of two step strides.
- Each leg takes the same number of one step strides.
- The total number of two step strides is no smaller than the total number of one step strides.
- The run starts with the left leg.
The legs alternate, and the total number of steps is always even. Rules 1 and 2 force the two legs to cover the same number of steps.
With six steps, each leg covers three, and there are 4 ways. Writing the right leg strides in bold: 2211, 2112, 1221, 1122. With eight steps there is only one way, 2222, because the two step strides cannot be outnumbered by the one step strides.
Given the total number of steps, count the ways to run them that satisfy all four rules.
Input
The first line contains the number of data sets ().
Each of the next lines contains a data set number and the total number of steps , separated by a space. is even and . Every data set is independent and is processed the same way.
Output
Print one line per data set. Each line holds the data set number , a single space, and the number of ways to run the steps that satisfy all four rules.