Compositions Missing a Sequence
InterviewTime limit1sMemory limit256 MB
Count the ordered compositions of n that use no part from the arithmetic progression starting at m with step k.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
A composition of an integer is an ordered list of positive integers whose sum is . Two compositions that use the same numbers in a different order count as different, which is what separates compositions from partitions. Written out in full, the compositions of the first few integers are:
1: {1}
2: {1+1, 2}
3: {1+1+1, 1+2, 2+1, 3}
4: {1+1+1+1, 1+1+2, 1+2+1, 1+3, 2+1+1, 2+2, 3+1, 4}
For 3, the compositions 1+2 and 2+1 are counted separately. As you may have guessed, an integer has compositions.
This problem puts a condition on the numbers a composition uses. A composition misses a set when no number in the composition belongs to . The compositions of the first few integers that miss the set of even integers are:
1: {1}
2: {1+1}
3: {1+1+1, 3}
4: {1+1+1+1, 1+3, 3+1}
No odd integer has a composition that misses the set of odd integers, and every composition of an even integer into even numbers alone pairs off with a composition of multiplied by 2.
Write a program that counts the compositions of which miss the arithmetic sequence .
Input
The first line contains one integer , the number of data sets (). Each data set is processed the same way and independently of the others.
Each of the next lines holds one data set. A line contains the data set number , followed by the three space separated integers , and (, ).
Output
Print one line for each data set. The line contains the data set number , a single space, then the number of compositions of which miss the given sequence.