DP || Backtracking+Memoization
\nclass Solution {\npublic:\n    int mod=1000000007;\n    \n    int dp[5001][6][16];\n    \n    int computeDP(int n, vector<int>& rollMax, int curr, int freq){\
```\nclass Solution {\npublic:\n    int mod=1000000007;\n    \n    int dp[5001][6][16];\n    \n    int computeDP(int n, vector<int>& rollMax, int curr, int freq){\n        if(n == 0) return 1;\n        if(dp[n][curr][freq]) return dp[n][curr][freq];\n        int ways=0;\n        for(int i=0; i < rollMax.size(); i++){\n            if(i == curr && freq < rollMax[i]){\n                ways=(ways%mod+computeDP(n-1, rollMax, i, freq+1)%mod)%mod;\n            }else if(i!=curr){\n                ways=(ways%mod+computeDP(n-1, rollMax, i, 1)%mod)%mod;\n            }\n        }\n        dp[n][curr][freq]=ways;\n        return dp[n][curr][freq];\n    }\n    \n    int dieSimulator(int n, vector<int>& rollMax) {\n        int ways=0;\n        for(int i=0; i < 6; i++){\n            ways=(ways%mod+computeDP(n-1, rollMax, i, 1)%mod)%mod;\n        }\n        return ways;\n    }\n};\n```
[]