C++ code
After wasting my time on bunch of combinatorial solution, eventually came up with dfs one.we can fill each possibilities with one of the 6 values,
but there are
After wasting my time on bunch of combinatorial solution, eventually came up with dfs one. 

we can fill each possibilities with one of the 6 values,
but there are constraints
the previous cannot come more than rollMax[i] number of times.

# Code
```cpp []
class Solution {
public:
    int mod = 1e9+7;
    int function(int n, int last, int count, vector<int>&rollMax, int dp[][7][16]){
        if(n==0) return 1;
        if(last!=-1)
        if(dp[n][last][count]!=-1) return dp[n][last][count];
        
        int ans = 0;
        for(int i = 1; i<=6; i++){
            if(i==last && count == rollMax[i-1]) continue;
            else if(i==last){
                ans= (ans + function(n-1, last, count+1, rollMax,dp))%mod;
            }
            else{
                ans= (ans + function(n-1, i, 1, rollMax,dp))%mod;
            }
        }
        if(last==-1) return ans;
        return   dp[n][last][count] = ans;
    }
    int dieSimulator(int n, vector<int>& rollMax) {
        int dp[n+1][7][16];
        memset(dp,-1,sizeof(dp));
        return function(n,-1,0, rollMax,dp);
    }
};
```
['C++']