Description
Suppose a pair of rabbits can produce a pair of rabbits a month (a female and a male), the next month after the birth of each rabbit is not reproductive ability, the third month after birth can also be a monthly birth of a team of rabbits, asked from a pair of newborn rabbit began, after several months after a total number of rabbits (assuming the rabbit did not die in the process).
The problem is the Italian mathematician Fibonacci (Fibonacci) in his 1202 edition of the Abacus book, the number of rabbits from the first pair of newborn rabbits started every month by the Fibonacci sequence. Input
The first number you enter is N, and then there are n numbers. Each number is one month m (m<=45). Output
The output is n rows, the total number of rabbits after each act m months. Sample Input 6 1 2 3 4 5 Sample Output 1 2 3 5 8 HINT
It's time to timeout.
Is it appropriate to use recursion to compute the Fibonacci sequence?
It is convenient to write with an array, and it is not timed out with a loop.
idea:
it's not appropriate to use the Fibonacci sequence. Tile defy results with Fibonacci input 45 and so on 10s to output a large number of strings. So the array is really strong invincible.
I'll take it. In fact, the 45 will exceed the bounds without LLD. But the OJ seems to be the same with Int.
There's also a bad habit of int arrays in a for loop. Don't learn.
Code:
#include <stdio.h>
#include <string.h>
int main ()
{
int i, n, S, C;
scanf ("%d", &s);
for (c = 1; C <= S; C + +)
{
scanf ("%d", &n);
Long long int a[47] = {1,2};
for (i = 2; I <= n; i++)
{
A[i] = a[i-1] + a[i-2];
printf ("%lld\n", a[n-1]);
return 0;
}