C++ Solution with DP Reasoning Simply Annotated
Code\n\nclass Solution {\npublic:\n    static int mod(int x) {\n        constexpr int M = 1000000007;\n        const int remain = x % M;\n        if (remain < 0
# Code\n```\nclass Solution {\npublic:\n    static int mod(int x) {\n        constexpr int M = 1000000007;\n        const int remain = x % M;\n        if (remain < 0) return remain + M;\n        return remain;\n    }\n\n    int firstDayBeenInAllRooms(vector<int>& nextVisit) {\n        vector<int> dp(nextVisit.size()); dp[0] = 0;\n\n        for (int i = 1; i < nextVisit.size(); i++) { \n            // First, get to previous spot (i - 1)\n            dp[i] = dp[i - 1];\n\n            // We then get sent back to nextVisit[i - 1]\n            dp[i] += 1; \n\n            // Work your way back to (i - 1)\n            dp[i] += mod(dp[i - 1] - dp[nextVisit[i - 1]]); \n            dp[i]  = mod(dp[i]);\n\n            // Since we already visited (i - 1), we can now proceed to i\n            dp[i] += 1; \n        }\n        \n        return mod(dp.back());\n    }\n};\n```
['C++']