原题链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2047
思路:
1 2 3
3 8 22
1 2 6 //O的数量
开两个数组记录
3 8 22
1 2 6
然后就做完了。
代码如下:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
long long int beefO[42]={0,1,2};
long long int ans[42]={0,3,8};
for(int i=3;i<41;i++)
{
beefO[i]=ans[i-1]-beefO[i-1];
ans[i]=beefO[i]*3+beefO[i-1]*2;
}
int n;
while(scanf("%d",&n)!=EOF)
{
cout<<ans[n]<<endl;
}
return 0;
}