C# DP
\npublic class Solution\n{\n  public int DieSimulator(int n, int[] rollMax)\n  {\n    var dp = new Dictionary<(int die, int seen), int>();\n\n    for (var die =
```\npublic class Solution\n{\n  public int DieSimulator(int n, int[] rollMax)\n  {\n    var dp = new Dictionary<(int die, int seen), int>();\n\n    for (var die = 0; die < 6; die++)\n      dp[(die, 1)] = 1;\n\n    for (var i = 1; i < n; i++)\n    {\n      var state = new Dictionary<(int, int), int>();\n\n      foreach (var key in dp.Keys)\n      {\n        for (var die = 0; die < 6; die++)\n        {\n          var nextkey = (key.die, key.seen);\n\n          if (key.die == die)\n          {\n            if (key.seen + 1 <= rollMax[die])\n              Add(dp, state, key, (die, key.seen + 1));\n          }\n          else\n          {\n            Add(dp, state, key, (die, 1));\n          }\n        }\n      }\n\n      dp = state;\n    }\n\n    var ans = 0;\n    foreach (var value in dp.Values)\n    {\n      ans += value;\n      ans %= (int)1e9 + 7;\n    }\n\n    return ans;\n\n    static void Add(\n      Dictionary<(int die, int seen), int> dp, \n      Dictionary<(int, int), int> state, \n      (int die, int seen) key, \n      (int die, int seen) nextkey)\n    {\n      if (!state.ContainsKey(nextkey))\n        state[nextkey] = 0;\n\n      state[nextkey] += dp[key];\n      state[nextkey] %= (int)1e9 + 7;\n    }\n  }\n}\n```
[]