C++ | O(N) time | O(1) space
\n\tint dieSimulator(int n, vector<int>& rollMax) {\n        int MOD = 1e9+7;\n        int dp[2][7][16];\n        for(int i=n-1;i>=0;i--){\n            for(int 
```\n\tint dieSimulator(int n, vector<int>& rollMax) {\n        int MOD = 1e9+7;\n        int dp[2][7][16];\n        for(int i=n-1;i>=0;i--){\n            for(int j=1;j<=6;j++){\n                for(int k=1;k<=rollMax[j-1];k++){\n                    if(i==n-1){\n                        dp[i%2][j][k]=1;\n                    }else{\n                        dp[i%2][j][k]=0;\n                        for(int d=1;d<=6;d++){\n                            if(d==j && k!=rollMax[j-1]){\n                                dp[i%2][j][k]=(dp[i%2][j][k]+dp[(i+1)%2][j][k+1])%MOD;\n                            }else if(d!=j){\n                                dp[i%2][j][k]=(dp[i%2][j][k]+dp[(i+1)%2][d][1])%MOD;\n                            }\n                        }\n                    }\n                }\n            }\n        }\n        int ans=0;\n        for(int i=1;i<=6;i++){\n            ans=(ans+dp[0][i][1])%MOD;\n        }\n        return ans;\n    }\n```
[]