C# 3D DP
\npublic class Solution {\n    int res = 0;\n    int [,,] dp;\n    public int DieSimulator(int n, int[] rollMax) {\n        dp = new int[n+1,7, 16];\n        \n
```\npublic class Solution {\n    int res = 0;\n    int [,,] dp;\n    public int DieSimulator(int n, int[] rollMax) {\n        dp = new int[n+1,7, 16];\n        \n        for(int i=1; i<7;i++)\n        {\n            //i is the current dice roll result.\n            res +=Helper(n-1, rollMax, i, 1);\n            res = (int)(res % (Math.Pow(10, 9) + 7));\n        }\n        return (int)(res % (Math.Pow(10, 9) + 7));\n    }\n    \n    public int Helper(int n, int[] rollMax, int i, int count)\n    {\n        \n        if(dp[n, i, count] > 0)\n        {\n            return dp[n, i, count];\n        }\n        \n        if(n == 0)\n        {\n            dp[n, i, count] = 1;\n            return dp[n, i, count];\n        }\n        else if(n < 0)\n        {\n            return 0;\n        }    \n        else\n        {\n            int ans = 0;\n            for(int j = 1; j < 7; j++)\n            {\n                //the last index != current index\n                if(i != j)\n                {   \n                    ans+=Helper(n-1, rollMax, j, 1);\n                    ans = (int)(ans%(Math.Pow(10, 9) + 7));\n                }\n                //the last index == current index but smaller than the limit\n                else if (i == j && count < rollMax[j-1])\n                {\n                    ans+=Helper(n-1, rollMax, j, count+1);\n                    ans = (int)(ans%(Math.Pow(10, 9) + 7));\n                }\n            }\n            dp[n, i, count] = (int)(ans % (Math.Pow(10, 9) + 7));\n\n            return ans;\n        }\n    }\n}\n```
[]