C++
\nclass Solution {\npublic:\n    int firstDayBeenInAllRooms(vector<int>& nextVisit) {\n        int n = nextVisit.size() ;\n        int M = 1e9 + 7 ;\n        ve
```\nclass Solution {\npublic:\n    int firstDayBeenInAllRooms(vector<int>& nextVisit) {\n        int n = nextVisit.size() ;\n        int M = 1e9 + 7 ;\n        vector<long long>dp(n) ;\n        dp[0] = 0 ;\n        for(int i = 0; i < n - 1; i++){\n            int j = nextVisit[i] ;\n            //dp[i+1] = \u7B2C\u4E00\u6B21\u5230\u9054i , \u8DF3\u56DE j (\u6B65\u6578+1) + dp[i] - dp[j]\n            //          i --> i+1, \u518D\u52A0 1   \n            dp[i+1] = ((dp[i] + 1 + dp[i] - dp[j] + M) + 1 ) % M ;\n        }\n        return dp[n-1] ;\n    }\n};\n```
['Dynamic Programming']