Top Down DP
\nclass Solution {\n    int MOD = 1000000007;\n    int dp[][][] = new int[5003][7][17];\n    \n    public int dieSimulator(int n, int[] nums) {\n        return 
```\nclass Solution {\n    int MOD = 1000000007;\n    int dp[][][] = new int[5003][7][17];\n    \n    public int dieSimulator(int n, int[] nums) {\n        return  solve(nums , 0 , n , 0 , 0);\n    }\n    \n    public int solve(int nums[] , int cnt , int n , int k , int kCnt) {\n        if(cnt == n) return 1;\n        if(dp[cnt][k][kCnt] != 0) return dp[cnt][k][kCnt];\n        \n        long ans = 0;\n        if(nums[k] > kCnt) \n            ans = (ans + solve(nums , cnt + 1 , n , k , kCnt + 1)) % MOD;\n        \n        for(int i = 0 ; i < 6 ; i++) {\n            if(i != k)\n              ans = (ans + solve(nums , cnt + 1 , n , i , 1)) % MOD;\n        }\n        \n        return dp[cnt][k][kCnt] = (int) ans % MOD;\n    }\n}\n```
['Dynamic Programming']