C++ 4 liners O(n) dp solution with explanation
Idea:\n1. Use dp[i] to record the number of steps to reach i\n->dp[i+1]=dp[i]+(dp[i]-dp[nextVisit[i]])+2\n->dp[i]: number of steps for 0 to reach i\n->dp[i]-dp[
Idea:\n1. Use dp[i] to record the number of steps to reach i\n->dp[i+1]=dp[i]+(dp[i]-dp[nextVisit[i]])+2\n->dp[i]: number of steps for 0 to reach i\n->dp[i]-dp[nextVisit[i]]: number of steps for nextVisit[i] to reach i\n->2: number of steps for i to reach i+1\n```\nint firstDayBeenInAllRooms(vector<int>& nextVisit) \n{\n\tlong n=nextVisit.size(),d=1000000007,dp[n+1];\n\tmemset(dp,0,sizeof(dp));\n\tfor(int i=0;i<n-1;i++) dp[i+1]=(2*dp[i]-dp[nextVisit[i]]+2+d)%d;\n\n\treturn dp[n-1];\n}\n```
[]