hdu 2047 阿牛的EOF牛肉串 (递推)
题意:一个由’E’ ‘O’ ‘F’ 组成的长度为n的字符串。‘O’不能相邻。。问方案数。。
思路:递推。。。蒙对了(误
考虑第n位,如果为’E’或者‘F’,此时对n-1位没有限制,答案为f[n-1],所以 一共是2×f[n-1]
如果为’O’,此时第n-1位为’E’或者’F’,此时对n-2位没有限制,答案为f[n-2],一共是2×f[n-2]
因此 f[i] = 2*(f[i-1]+f[i-2])
1/* ***********************************************
2Author :111qqz
3Created Time :2016年07月27日 星期三 15时22分19秒
4File Name :code/hdu/2047.cpp
5************************************************ */
6
7#include <cstdio>
8#include <cstring>
9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=42;
34int n;
35LL f[N];
36int main()
37{
38 #ifndef ONLINE_JUDGE
39 freopen("code/in.txt","r",stdin);
40 #endif
41
42 f[1] = 3;
43 f[2] = 8;
44 for ( int i =3 ; i < N ; i++) f[i] =2LL*(f[i-1]+f[i-2]);
45
46 while (~scanf("%d",&n))
47 {
48 printf("%lld\n",f[n]);
49 }
50
51 #ifndef ONLINE_JUDGE
52 fclose(stdin);
53 #endif
54 return 0;
55}