[Explanations] - hdu EOF bull beef string [recurrence]

EOF string of bull beef

This year's summer ACM training team a total of 18 people, divided into six teams. There is a team called the EOF by 04 of the bull, XC and 05 of COY composition. Training in a common life, we established a deep friendship, bull ready to do something to commemorate this burning passion, thought for a moment, the bull brought from home a piece of the finest beef jerky, ready the above carved only of a string of "E" "O" "F " n, three kinds of characters (which may be only one or two characters, but there must be no other characters), while inhibiting the sequence bull O adjacent situation appeared, he believes, "OO" looks like angry eyes, the effect is not good.
You, NEW ACMer, EOF admirers, can help a bull to count how many different strings to meet the requirements of a total of it?
PS: bull there is a little secret, is ready to put the EOF engraved with beef jerky, as a mysterious gift to Hangzhou Electric 50th Anniversary, it is conceivable when the president took the piece of beef jerky how happy! Here, please allow me, on behalf of ACMer Hang electricity thanks to the bull!
Thanks again!

Input

Input data comprising a plurality of test cases, one row for each test case, the composition of the integer n a, (0 <n <40).

Output

For each test case, output a full coating to meet the requirements, the output of each row for instance.

Sample Input

1
2

####Sample Output

3
8

AC Code

#include <stdio.h>
int main(void)
{
    int a, b, n, i;
    long long arr[45] = {0};
    arr[0] = 0;
    arr[1] = 3;
    arr[2] = 8;
    for(i = 3; i <= 40; i ++){
        arr[i] = 2 * (arr[i - 1] + arr[i - 2]);
    }
    while(scanf("%d",&n) != EOF){
        printf("%lld\n",arr[n]);
    }
    return 0;
}

Thinking

The sake of being more complex, pour the sake of feeling okay;

Reflections on the last character may only have three cases: E, F, O;

The final total coating method is F (n);

When E is the penultimate character can be easily coated, and therefore the number of coating for this method is: F (n-1);

When F is the penultimate character may be easily coated, coating methods and therefore also for this number: F (n-1);

When the time is O

Second last character not just because of two consecutive O does not meet the requirements, so when O has been divided into two conditions E or F.

In the case of the last two characters of the EO, the antepenultimate characters can be easily, so this coating is F (n-2);

In the case of the last two characters of the FO, antepenultimate characters may be easily, so this coating is also F (n-2);

This time has been completed in consideration of all the stresses, F. (N-) 2 = F. (. 1-n-) +2 F. (N--2);

You can also use an iterative;
pay attention to find the law;

Published 34 original articles · won praise 2 · Views 900

Guess you like

Origin blog.csdn.net/Kapo1/article/details/103541039