[Java] readable DP solution
\nclass Solution {\n    private final long M = 1000000007;\n    \n    public int dieSimulator(int n, int[] rollMax) {\n        long[][] dp = new long[n+1][7];\n
```\nclass Solution {\n    private final long M = 1000000007;\n    \n    public int dieSimulator(int n, int[] rollMax) {\n        long[][] dp = new long[n+1][7];\n        dp[0][6] = 1;\n        \n        for (int i = 1; i <= n; i++) {\n            for (int j = 0; j < 6; j++) {\n                dp[i][j] = dp[i-1][6];\n                if (i > rollMax[j]) {\n                    long diff = dp[i-rollMax[j]-1][6] - dp[i - rollMax[j]-1][j];\n                    if (dp[i][j] < diff) dp[i][j] += M;\n                    dp[i][j] -= diff;\n                }   \n                dp[i][6] += dp[i][j];\n            }\n            dp[i][6] %= M;\n        }\n        return (int) dp[n][6];\n    }\n}\n```
[]