Ox's EOF Beef skewer

Source: Internet
Author: User
Tags time limit
Ox's EOF Beef skewer

http://acm.hdu.edu.cn/showproblem.php?pid=2047

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 35402 Accepted Submission (s): 16673

problem Description

This year's ACM summer training Team A total of 18 people, divided into 6 teams. There is a team called EOF, consisting of 04 levels of ox, XC, and Level 05 coy. In the common training life, we have established a deep friendship, a cow ready to do something to commemorate the burning years of passion, think, a cow from home brought a fine beef jerky, ready to carve a length of n only by "E" "O" "F" Three characters of a string (can only one or two characters, but absolutely no other characters), the Ox also prohibits the appearance of o adjacent in the string, he thought, "OO" looks like angry eyes, the effect is not good.

You, NEW Acmer,eof's admirer, can help the bull figure out how many different strings meet the requirements.

PS: Ox also has a small secret, is ready to put this engraved with EOF beef dry, as a mysterious gift for Hangzhou Electric 50 Anniversary celebration, can imagine, when the headmaster took this piece of beef dry time how happy. Here, please allow me to express my gratitude to Aniu on behalf of Hangzhou Electric Acmer.

Thanks again.

Input

The input data contains multiple test instances, one row per test instance, and an integer n, (0<n<40).

Output

For each test instance, output all of the required coating methods, one row for each instance output.

Sample Input

1

2

Sample Output

3

8

Author

Lcy

This is a recursive topic:

For a string to meet the requirements, the only condition is not to have an attached O

Start a discussion from the first character

1. Assuming that the character is O, then the character behind him must not be O, which is one of the e,f, in which case the number of scenarios is 2*f (n-2)

2. If this character is not o, then the character behind him is not restricted, there are 2 cases in the first position, so the number of scenarios in this case is 2*f (n-1)

Sum up

The recursive equation is f (n) =2* (f (n-1) +f (n-2))

#include <iostream>
#include <cstdio>
using namespace std;
Long long f[50];
int main () {
    f[0]=0;f[1]=3;f[2]=8;
    For (long long i=3;i<=40;i++) {
        f[i]=2* (f[i-1]+f[i-2]);
    } int A;
    while (scanf ("%d", &a)!=eof) {
        printf ("%lld\n", F[a]);
    }
}

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.