`
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <list>
using namespace std;
//分析题意,我们知道这是一道排列计数问题。而且,题意的要求是对于给定字符串长度n,给出对应的方案数m。我很容易联想到“f(n) = m”这样的函数关系。并且,题目中的限制条件只有“两个O不能相邻”。计数 + 简单限制 = 递推。接下来的问题就是求出递推公式了。
//
//* 第n格取“O”:
//
// ----------------------------------
// | | | | …… | | | O |
// ----------------------------------
// 1 2 3 n-2 n-1 n
//
//
// -----------------------------------
// | | | | …… | | E | O |
// -----------------------------------
// 1 2 3 n-2 n-1 n
//
//
// -----------------------------------
// | | | | …… | | F | O |
// -----------------------------------
// 1 2 3 n-2 n-1 n
//
// 对于第n格取“O”的情况,为了保证两个“O”不相邻,n-1格有两种可能,即“E”、“F”。对于余下的n-2格,由于第n-1格不取“O”,所以第n-2格不受n-1格的限制。其排列数等于f(n-2)。
//
//* 第n格不取“O”:
//----------------------------------
//| | | | …… | | | E |
//----------------------------------
// 1 2 3 n-2 n-1 n
//
//
//----------------------------------
//| | | | …… | | | F |
//----------------------------------
// 1 2 3 n-2 n-1 n
//
// 对于第n格不取“O”的情况,即取“E”、“F”。对于余下的n-1格,由于第n格不取“O”,所以,第n-1格不受n格的限制。其排列数等于f(n-1)。
//
// 综上,f(n) = 2*f(n-2) + 2*f(n-1)
// = 2*(f(n-2) + f(n-1))
long long f(int n){
if(n==1)return 3;
if(n==2)return 8;
return f(n-1)*2+f(n-2)*2;
}
int main(){
int n;
while (cin>>n) {
cout<<f(n)<<endl;
}
return 0;
}