Explanation for Rookies like meself [1 Line DP magic!]
The problem has a strong DP pattern to it - The minimum days to reach Room i is completely dependent on smaller subproblems that have been solved before.\n The 
* The problem has a strong DP pattern to it - The minimum days to reach Room i is completely dependent on smaller subproblems that have been solved before.\n* The hard part is only to identify the recurrence relation.\n* Once we define the DP table, it is easy to see that dp[0] will be 0;\n* The most important observation is that you can only reach the room i via room i - 1 and hence we atleast need dp[i - 1] days to reach ith room and then some more.\n* But we will also need (dp[i - 1] - dp[next[i - 1]]) days. Why?\n* Well room i - 1 will send us back to room (next[i - 1]) because of the odd even rules and from there we will have to return to room i - 1 again. This will take us  (dp[i - 1] - dp[next[i - 1]]) days.\n* So the total days will be  (dp[i - 1] + dp[i - 1] - dp[next[i - 1]]). +2 extra days to reach room i.\n* Draw the dp table and try this to get the complete picture. A fully written explanation is not possible. Once you get a hang of the recurrence relation on paper, it will click.\n* Overall a tough problem to crack in a contest or interview. Recursive solution is simple but cracking the dp idea for noobs like me is still pretty far away.\n \n---------------------------------------------\n\n\n\n\n\n\n```\n    int firstDayBeenInAllRooms(vector<int>& next) {\n        \n        int n = next.size(); int mod = pow(10, 9) + 7;\n        vector<long> dp(n); dp[0] = 0;\n        \n        for(int i = 1 ; i < n ; i++) \n            dp[i] = (dp[i - 1] + dp[i - 1] - dp[next[i - 1]] + 2 + mod) % mod;\n        \n        return dp.back();\n    }\n```
[]