CCF 100002. Take number game __ccf-difficulty I.

Source: Internet
Author: User
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;  




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.