Java dp
step one : we reach  i-1  with dp[i-1] steps;\nstep two:  we rereach  i-1 with dp[i-1] - dp[nv[i-1]]+1   steps , since dp[i-1] may be less than dp[nv[i-1]],  so
step one : we reach  i-1  with dp[i-1] steps;\nstep two:  we rereach  i-1 with dp[i-1] - dp[nv[i-1]]+1   steps , since dp[i-1] may be less than dp[nv[i-1]],  so add a mod\nstep three: we jump from i-1 to i with  1 step;\n\n\nwe can see that when we reach a new idx , the count before idx is always even, means that we restart at nv[idx] with odd ; so if we want to rereach this idx , we must use dp[i-1] - dp[nv[i-1]] + 1 steps;\n\n```\nclass Solution {\n    public int firstDayBeenInAllRooms(int[] nv) {\n        int len = nv.length;\n        long[] dp = new long[len];\n        dp[1] = 2;\n        int mod = 1000000007;\n        for(int i = 2 ; i < len ; i++){\n            dp[i] = dp[i-1] + dp[i-1] + mod - dp[nv[i-1]] + 2;\n            dp[i] %= mod;\n        }\n        return (int)dp[len-1];\n    }\n}\n```
[]