A Population of Rabbits
InterviewTime limit1sMemory limit256 MB
Count rabbit pairs alive in month M given lifespan D and breeding ages up to R, starting from one newborn pair.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Simulation
- Solved
- No attempts yet
Problem
A hypothetical population of rabbits follows fixed rules.
- In the first month the population is one pair of newborn rabbits.
- A pair can mate starting the month after it is born.
- Every pair that can mate does so, in every month.
- A pair that mates gives birth to one male and one female, a new pair, in the next month.
- A pair lives until the month its age reaches months, and it stops breeding once its age passes months, where .
An age is 1 month in the month a pair is born and grows by 1 each month. So a pair born in month is alive in months through , and it mates in every month where its age is at least 2 and at most , that is in months through .
Take and . A pair lives three months and mates twice. The first pair is born in month 1, mates in month 2, and its first child pair is born in month 3. That same pair mates again in month 3, so a second child pair is born in month 4. The first pair dies in month 4, so it is not counted in the population of month 4.
Given , and , write a program that counts the rabbit pairs alive in month .
Input
The first line contains the number of test cases (). Each of the next lines contains three positive integers , , . Here is the age at which a pair dies, is the age after which a pair stops breeding, and is the month whose population you report. The bounds are , , and .
Output
For each test case print one line of the form Case #n: k, where is the test case number starting at 1 and is the number of rabbit pairs alive in month .