HDU2047 阿牛的EOF牛肉串【水题】
原创
©著作权归作者所有:来自51CTO博客作者ITCharge的原创作品,请联系作者获取转载授权,否则将追究法律责任
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2047
题目大意:
有一个长度为N的字符串,只有'E'、'O'、'F'组成, 字符串中禁止出现"OO"相连的情况。
问:最多有多少组不同的字符串满足情况。
思路:
根据讨论区来的思路。设N位字符串,最后一位是'O'的字符串个数为a[N],最后一位不是'O'字符
的字符串个数为b[N],总的 字符串个数为f[N],则:
f[N] = a[N] + b[N]
a[N] = b[N-1]
b[N] = 2*f[N-1]
则推出:f[N] = 2*(f[N-1] + f[N-2])。
设f[1] = 3,f[2] = 8。
AC代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
__int64 f[44];
int main()
{
f[1] = 3;
f[2] = 8;
for(int i = 3; i <= 40; ++i)
f[i] = 2*(f[i-1] + f[i-2]);
int N;
while(~scanf("%d",&N))
{
printf("%I64d\n",f[N]);
}
return 0;
}