C++ | Detailed Explanation
Idea is to store the results of each die roll in a 2D array and reuse them for next roll.\nways[n][face]\n- n represets the number of rolls \n- face represents 
Idea is to store the results of each die roll in a 2D array and reuse them for next roll.\nways[n][face]\n- n represets the number of rolls \n- face represents the die values from 0 - 6\n\n1. For each roll have to first calculate how many combinations are there at current face value and current roll(considring the max consecutive times limit) and finally we sum up the total combinations possible for the current roll for all 0-6 faces.\n\n2. For each face value 0-6, we can check how many consecutive times we can repeat this at the current roll.  \n(ways[roll-i][6]-ways[roll-i][face]) - Whenever we consider the number of combinations possible starting from the current roll, then we have to go to previous roll total combinations and take away the combinations of current face value from previous roll so that there won\'t be any invalid counting. So if n is 2, then we do this with n=1 and n=0 until we reach rollMax limit. \n\n ((ways[roll-i][6]-ways[roll-i][face])+MOD)%MOD;  - If any of you face problem with MOD, then please note that we have to add MOD while subtracting two MOD\'ed values and then MOD again. This will help you not to get -ve overflow. Why we are adding MOD and how it works is.\n \n10 - 6 = 4\n10%5 - 6%5 = 0-1 = -1\nHere both -1 and 4 are actually same but inorder to get the +ve value we can do -1+5(MOD) value = 4.This is a different topic, but it is required in this problem so I thought of explaining this.\n\n```\nclass Solution {\npublic:\n    int dieSimulator(int n, vector<int>& rollMax) \n    {\n        int MOD=1000000007;\n        int sz = (int)rollMax.size();\n        vector<vector<int>> ways(n+1,vector<int>(sz+1,0));\n        //ways[n(number of rolls)][faces{0-5} and 6th face will have total combinations]\n        //When we do not roll the die \n        ways[0][6] = 1;\n        \n        //when we roll die only once\n        for(int i=0;i<6;i++)\n            ways[1][i] = 1;\n        //total number of combinations we can have when we roll only once\n        ways[1][6] = 6;\n        long long sum=0;\n        //When we roll more than once\n        for(int roll=2;roll<=n;roll++)\n        {\n            sum = 0;\n            for(int face=0;face<6;face++)\n            {\n                //for each face value we have to go up given levels starting from current roll.\n                for(int i=1;i<rollMax[face]+1;i++)\n                {\n                    if(roll-i<0)\n                        break;\n                    //Inorder to use the current face for the current roll, we have to subtract the combinations required for the previous roll and keep doing this upto the rollMax[face]\n                    int a = ((ways[roll-i][6]-ways[roll-i][face])+MOD)%MOD;\n                    int b = ways[roll][face];\n                    ways[roll][face]=(a+b)%MOD;\n                    \n                }\n                sum=(sum+ways[roll][face])%MOD;\n            }\n            ways[roll][6] = sum; //total number of combinations at this roll of die\n        }\n        return ways[n][6];\n        \n    }\n};\n```
[]