concise C++ Solution. recursion + memo.
\nclass Solution {\npublic:\n    long long M = 1e9 + 7;\n    int m[5001][6][16];\n    int dieSimulator(int n, vector<int>& rollMax) {\n        memset(m, -1, siz
```\nclass Solution {\npublic:\n    long long M = 1e9 + 7;\n    int m[5001][6][16];\n    int dieSimulator(int n, vector<int>& rollMax) {\n        memset(m, -1, sizeof(m));\n        return f(n, 0, 0, rollMax);\n    }\n    \n    long long f(int n, int roll, int k, vector<int>& rollMax) {\n        if(n == 0) \n            return rollMax[roll] < k ? 0 : 1;\n        if(rollMax[roll] < k)\n            return 0;\n        if(m[n][roll][k] >= 0) return m[n][roll][k];\n        long long res = 0;\n        for(int i = 0; i < 6; ++i)\n            res += f(n - 1, i, roll == i ? k + 1 : 1, rollMax);\n        res %= M;\n        m[n][roll][k] = res;\n        return res;\n    }\n};\n```
[]