Time Limit: 1000 MS Memory Limit: 32768 KB
64-bit integer IO format: %lld , %llu Java class name: Main
题目链接:http://acm.hrbust.edu.cn/vj/index.php?c=problem-problem&id=75523
Cc用了药水之后状态全满,现在出现在他们眼前的是一个悬崖,悬崖之间有一座不停在变换着颜色的桥,wd发现桥是由一个个变换着颜色的板组成,每次只能够从一个板走到相邻的一块板上,而且不能回头。每块板只会在红,黄,蓝三种颜色之间变换。如果想要到达对岸必须经过此桥,wd突然发现了桥的一个玄妙的的地方,就是经过的时候,连续的三个板如果颜色都不相同,就会有杯具发生...例如:经过的时候如果走过的连续三个是“红黄蓝”就会不妙,但是“红红蓝”“蓝蓝蓝”等情况就可以。
Cc问wd:到达对岸的方法一共有多少种?

多组测试数据,第一行一个整数T,表示数据的组数。
接下来T行,每行一个整数n,表示桥是由n块板组成。
2
2
3
9
21
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;
/** Constant List .. **/ //{
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;
const int maxn = 1000001;
LL a[maxn];
int main()
{
#ifdef DoubleQ
freopen("in.txt","r",stdin);
#endif
int T;
scanf("%d",&T);
a[1] = 3;
a[2] = 9;
for(int i = 3 ; i < maxn ; i ++)
{
a[i] = 3 * (a[i-2]) + 2 * (a[i-1] - a[i-2]);
}
while(T--)
{
int n;
scanf("%d",&n);
printf("%lld\n",a[n]);
}
}
原文:http://blog.csdn.net/u013447865/article/details/40707287