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])
/* ***********************************************
Author :111qqz
Created Time :2016年07月27日 星期三 15时22分19秒
File Name :code/hdu/2047.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6const int N=42;
7int n;
8LL f[N];
9int main()
10{
11 #ifndef ONLINE_JUDGE
12 freopen("code/in.txt","r",stdin);
13 #endif
1 f[1] = 3;
2 f[2] = 8;
3 for ( int i =3 ; i < N ; i++) f[i] =2LL*(f[i-1]+f[i-2]);
1 while (~scanf("%d",&n))
2 {
3 printf("%lld\n",f[n]);
4 }
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}