HDUOJ2047: bull beef string EOF

Copyright: qq836678589 https://blog.csdn.net/weixin_43924623/article/details/91432681

EOF string of bull beef

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 50597 Accepted Submission(s): 23893

Problem Description
This year's ACM summer 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

#include<iostream>
using namespace std;
int main(){
	int n,i;
	long long a[41]={0,3,8};
	for(i=3;i<40;i++)
		a[i]=2*a[i-1]+2*a[i-2];
	while(cin>>n){
		cout<<a[n]<<endl;
	}
	return 0;
}

总结:
a[n]=x[n]+y[n]
x[n]=y[n-1]
y[n]=2a[n-1]
a[n]=2a[n-1]+2a[n-2]

Guess you like

Origin blog.csdn.net/weixin_43924623/article/details/91432681