Recursive DP in C++ Easy to Understand
\nclass Solution {\npublic:\n    int mod=1e9+7;\n    int dp[5005][9][20];\n    int recur(int x,int last,int occ,vector<int>& rollmax)\n    {\n        if(x==0)\n
```\nclass Solution {\npublic:\n    int mod=1e9+7;\n    int dp[5005][9][20];\n    int recur(int x,int last,int occ,vector<int>& rollmax)\n    {\n        if(x==0)\n            return 1;\n        if(dp[x][last][occ]!=-1)\n            return dp[x][last][occ];\n        int ans=0;\n        for(int i=1;i<=6;i++)\n        {\n            if(i==last && occ<rollmax[i-1])\n                ans+=(recur(x-1,i,occ+1,rollmax)%mod);\n            else if(i==last && occ==rollmax[i-1])\n                continue;\n            else if(i!=last && rollmax[i-1]>=1)\n                ans+=(recur(x-1,i,1,rollmax)%mod);\n            ans=ans%mod;\n        }\n        return dp[x][last][occ]=ans;\n    }\n    int dieSimulator(int n, vector<int>& rollMax) {\n        memset(dp,-1,sizeof(dp));\n        return recur(n,7,0,rollMax);\n    }\n};\n```
[]