CF 166E Tetrahedron
Posted shenben
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF 166E Tetrahedron相关的知识,希望对你有一定的参考价值。
You are given a tetrahedron. Let‘s mark its vertices with letters A, B, C and D correspondingly.
An ant is standing in the vertex D of the tetrahedron. The ant is quite active and he wouldn‘t stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. The ant just can‘t stand on one place.
You do not have to do much to solve the problem: your task is to count the number of ways in which the ant can go from the initial vertex D to itself in exactly n steps. In other words, you are asked to find out the number of different cyclic paths with the length of n from vertex D to itself. As the number can be quite large, you should print it modulo 1000000007 (109 + 7).
The first line contains the only integer n (1 ≤ n ≤ 107) — the required length of the cyclic path.
Print the only integer — the required number of ways modulo 1000000007 (109 + 7).
2
3
4
21
The required paths in the first sample are:
- D - A - D
- D - B - D
- D - C - D
【题意】
给一个四面体,从顶点D沿棱走n步回到D,问方案数。
【分析】
引自__http://www.cnblogs.com/zyf0163/p/4318036.html
【代码】
#include<cstdio>
using namespace std;
const int N=1e7+5;
const long long mod=1e9+7;
int n;long long f[N];
int main(){
f[1]=0;f[2]=3;
scanf("%d",&n);
for(int i=3;i<=n;i++){
f[i]=2*f[i-1]+3*f[i-2];
f[i]%=mod;
}
printf("%I64d
",f[n]);
return 0;
}
以上是关于CF 166E Tetrahedron的主要内容,如果未能解决你的问题,请参考以下文章