Java dp
\npublic int dieSimulator(int n, int[] r) {\n        long mod = (long) (Math.pow(10, 9) + 7);\n        if (n == 1) return 6;\n        long[][] dp = new long[n][
```\npublic int dieSimulator(int n, int[] r) {\n        long mod = (long) (Math.pow(10, 9) + 7);\n        if (n == 1) return 6;\n        long[][] dp = new long[n][7];\n        for (int i = 0; i < 6; i++) {\n            dp[0][i] = 1;\n        }\n        dp[0][6] = 6;\n        for (int i = 1; i < n; i++) {\n            for (int j = 0; j < 6; j++) {\n                long sum = dp[i - 1][6];\n                if (i - r[j] == 0) sum--;   // exclude 111, say i = 2, r[j] = 2;\n                if (i - r[j] - 1 >= 0) sum = (sum -dp[i - r[j] - 1][6] + dp[i - r[j] - 1][j]  + mod) % mod; // exclude 2111, 3111, but not 1111\n                dp[i][j] = sum;\n                dp[i][6] = (dp[i][6] + sum) % mod;\n            }\n        }\n        return (int) dp[n - 1][6];\n    }\n```\nDebug thanks to ref: https://leetcode.com/problems/dice-roll-simulation/discuss/403756/Java-Share-my-DP-solution
[]