Take a few games
Topic Description
Let's play a game: The natural number 1 to n, in order in a row, you can take any number, but the adjacent two can not be taken away at the same time. If you can figure out how many kinds of lijiganjun, then you will be rewarded by the gods.
input
Contains only one number n (1< N < 50).
Output
Contains only one number ——— your answer.
Sample Input
5
Sample Output
13
problem Analysis: The core idea of this problem is the Fibonacci sequence. First consider the relationship between F[i] and f[i-1], the equivalent of i-1 in the sequence of the last increase in an I, then there are the following two cases, one is to take I, so i-1 can not be taken together, because the adjacent can not be taken together, which means that this situation is equivalent to the former i-2 and I take , that is, f[i-2]; the second situation is to keep I finally take, also became the first i-1, that is f[i-1], f[i] for two kinds of circumstances, that is, f[i] = F[i-1] + f[i-2]. The above is the idea, the following is I do not understand the place, first we assume that N is 2 o'clock, the output should not be 2. That is to say (1,2) and (2,1) This situation, but I read the other People's blog is n = 2 o'clock result is 3, this makes me very ignorant, so that my results are always wrong with others, that is, they calculate the n = 5 results and I calculate the n = 6 results, which big guy can explain to me. The following is the AC code (note that the AC code, not My Code):
#include <iostream>
using namespace std;
typedef unsigned long long ull;
Ull str[100];
ull fib () //The function is used to play the table
{
str[1] = 2;
STR[2] = 3;
for (int i=3; i<=70; i++)
{
Str[i] = str[i-1] + str[i-2]; Fibonacci Sequence table Formula
}
int main ()
{
fib (); Call the FIB () function
int n;
while (Cin>>n)
{
cout<<str[n]<<endl;
}
return 0;