CF166E.Tetrahedron
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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).
给你一个四面体。我们将其顶点分别标记为字母 A、B、C 和 D。

一只蚂蚁位于四面体的顶点 D 上。这只蚂蚁非常活跃,不会静止不动。在每一时刻,它都会沿着四面体的一条边从一个顶点移动到另一个顶点。蚂蚁绝不会停留在原地。
你只需完成一项简单任务:计算蚂蚁从起始顶点 D 出发,恰好经过 n 步后返回顶点 D 的路径总数。换言之,你需要求出从顶点 D 到自身、长度为 n 的不同环形路径的数量。由于结果可能非常大,请将答案对 1000000007(即 109+7)取模后输出。
输入格式
The first line contains the only integer n (1 ≤ n ≤ 107) — the required length of the cyclic path.
第一行包含唯一一个整数 n(1≤n≤107)—— 所需的环形路径长度。
输出格式
Print the only integer — the required number of ways modulo 1000000007 (109 + 7).
输出唯一的整数——所求的方案数对 1000000007(即 109+7)取模的结果。
输入输出样例
输入#1
2
输出#1
3
输入#2
4
输出#2
21
说明/提示
The required paths in the first sample are:
- D - A - D
- D - B - D
- D - C - D
第一个样例中所需的路径为:
- D - A - D
- D - B - D
- D - C - D
输入解题思路,AI测评打分。不知道怎么写?