https://codeforces.com/problemset/problem/407/B
这个题目是一个dp,有那么一点点的递归的意思,这个应该算一个找规律的dp,
dp[i]定义为第一次到第i个房间的步数,
转移方程 dp[i]=dp[i-1]+dp[i-1]-dp[p[i]]+1;
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#define inf 0x3f3f3f3f
#define debug(x) cout<<"-----"<<" x = "<<x<<"-----"<<endl
using namespace std;
typedef long long ll;
const int maxn = 5e3 + 10;
const ll mod = 1e9 + 7;
ll dp[maxn];
int p[maxn];
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
dp[2] = 2;
dp[1] = 0;
for(int i=2;i<=n;i++)
{
dp[i+1] = (2 * dp[i]%mod - dp[p[i]]%mod + 2+mod)%mod;
}
printf("%lld\n", dp[n + 1]%mod);
return 0;
}