c++ dp o(n)
\nclass Solution {\npublic:\n    int firstDayBeenInAllRooms(vector<int>& nextVisit) {\n        int n = nextVisit.size();\n        int v[n];//v[i] is the first #
```\nclass Solution {\npublic:\n    int firstDayBeenInAllRooms(vector<int>& nextVisit) {\n        int n = nextVisit.size();\n        int v[n];//v[i] is the first # for room i\n        v[0] = 0;\n        int ans = 1;\n        for(int i=0; i<n-1; i++)\n        {\n            ans = ((ans - v[nextVisit[i]] + 1000000007) % 1000000007 + ans + 1) %(1000000007);\n            v[i+1] = ans - 1;\n        }\n        return (ans-1+ 1000000007)% 1000000007;\n    }\n};\n```\n
[]