Generations of Tribbles
InterviewTime limit2sMemory limit128 MB
Compute the nth term of a four-term Fibonacci-like recurrence for up to 68 test cases with precomputation.
- Level
Easy3 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
Koong has nothing to do in the army. So he wants to build a Fibonacci sequence of his own. The usual Fibonacci is too simple for him, so he wanted something heavier, and he came up with the sequence below. Writing his own Fibonacci function as ,
n < 2 : 1
n = 2 : 2
n = 3 : 4
n > 3 : koong(n - 1) + koong(n - 2) + koong(n - 3) + koong(n - 4)
Compute Koong's Fibonacci yourself.
Input
The first line contains the number of test cases (). Each of the next lines contains one integer (), the index of the Fibonacci value to compute.
Output
For each test case, print Koong's Fibonacci value on its own line.