CF407B.Long Path
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one.
The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number p__i, where 1 ≤ p__i ≤ i.
In order not to get lost, Vasya decided to act as follows.
- Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1.
- Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room p__i), otherwise Vasya uses the first portal.
Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end.
一天,小瓦夏发现自己身处一个由 n+1 个房间组成的迷宫中,房间编号从 1 到 n+1。初始时,瓦夏位于第 1 个房间,而要走出迷宫,他需要到达第 n+1 个房间。
迷宫的结构如下:迷宫中的每个房间都有两个单向传送门。考虑编号为 i 的房间(1≤i≤n),可通过第一个传送门从该房间移动到编号为 i+1 的房间;也可通过第二个传送门从该房间移动到编号为 pi 的房间,其中 1≤pi≤i。
为了不迷路,瓦夏决定按如下方式行动:
- 每次瓦夏进入某个房间时,他都会在该房间天花板上画一个叉号。初始时,瓦夏在第 1 个房间的天花板上画了一个叉号。
- 假设瓦夏当前位于房间 i,且已在该房间天花板上画过一个叉号。那么,若此时天花板上的叉号总数为奇数,瓦夏就使用第二个传送门(通向房间 pi);否则,瓦夏使用第一个传送门。
请帮助瓦夏计算:他最终到达房间 n+1 所需使用的传送门总次数。
输入格式
The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers p__i (1 ≤ p__i ≤ i). Each p__i denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room.
第一行包含一个整数 n(1≤n≤103)—— 房间的数量。
第二行包含 n 个整数 pi(1≤pi≤i)。每个 pi 表示:若某人在第 i 个房间中使用第二个传送门,则他所能到达的房间编号。
输出格式
Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7).
输出一个整数——男孩逃出迷宫所需的传送门移动次数。由于该数可能非常大,请对 1000000007(即 109+7)取模后输出。
输入输出样例
输入#1
2 1 2
输出#1
4
输入#2
4 1 1 2 3
输出#2
20
输入#3
5 1 1 1 1 1
输出#3
62
输入解题思路,AI测评打分。不知道怎么写?