C++ || Recursion+DP(tabulation) || beginner friendly || intutive
Intuition\nif start=1, sequence can be -> (1)(...), (11)(...), (111)(...), (1111)(...)\n\n# Approach\nSee recursive code:\n\n    int fun(int n, int start, vecto
# Intuition\nif start=1, sequence can be -> (1)(...), (11)(...), (111)(...), (1111)(...)\n\n# Approach\nSee recursive code:\n```\n    int fun(int n, int start, vector<int>& rollmax)\n    {\n        //eg start = 1 if possible according to rollmax: -> (1)(...), (11)(...), (111)(...), (1111)(...)\n\n        if(n==0) return 0;\n\n        int ans=0;\n        for(int taken=1;taken<=rollmax[start-1];taken++) //i is how many starts we have taken in beginning\n        {\n            if(taken==n) //can not take more than n\n            {\n                ans++;\n                break;\n            }\n\n            for(int next_start=1;next_start<=6;next_start++)\n            {\n                if(next_start!=start)\n                {\n                    if(n-taken>0)\n                    {\n                        ans+=fun(n-taken,next_start,rollmax);\n                        ans%=mod;\n                    }\n                }\n            }\n        }\n        return ans;\n    }\n\n//-----------------------------------\n//main: \n        int ans=0;\n        for(int start=1;start<=6;start++)\n        {\n            ans+=fun(n,start,rollMax);\n            ans%=mod;\n        }\n        return ans;\n\n```\n\n# Complexity\n- Time complexity:\nO(N^6^maxRoll[i])\n\n- Space complexity:\n- O(N*6)\n\n# Code\n```\nclass Solution {\npublic:\n    const int mod=1e9+7;\n\n    int dieSimulator(int n, vector<int>& rollMax) {\n\n        // Intution:  if start=1, sequence can be -> (1)(...), (11)(...), (111)(...), (1111)(...)\n\n        int dp[n+1][7];\n        memset(dp,0,sizeof(dp));\n\n        for(int i=1;i<=n;i++)\n        {\n            for(int start=1;start<=6;start++)\n            {\n                int ans=0;\n                for(int taken=1;taken<=rollMax[start-1];taken++)\n                {\n                    if(taken==i) //can not take more than i\n                    {\n                        ans++;\n                        break;\n                    }\n                    \n                    for(int next_start=1;next_start<=6;next_start++)\n                    {\n                        if(next_start!=start)\n                        {\n                            ans+=dp[i-taken][next_start];\n                            ans%=mod;\n                        }\n                    }\n                }\n\n                dp[i][start]=ans;\n            }\n        }\n\n        int f_ans=0;\n        for(int start=1;start<=6;start++) \n        {\n            f_ans+=dp[n][start];\n            f_ans%=mod;\n        }\n        return f_ans;\n    }\n};\n\n```
['C++']