3D DP + Memoization | C++
Code\n\nclass Solution {\npublic:\n\n    #define ll long long\n\n    int n;\n    vector<int>a;\n    ll mod=1e9+7;\n\n    ll dp[5001][7][16];\n\n    ll f(int i, 
# Code\n```\nclass Solution {\npublic:\n\n    #define ll long long\n\n    int n;\n    vector<int>a;\n    ll mod=1e9+7;\n\n    ll dp[5001][7][16];\n\n    ll f(int i, int last, int cnt){\n        if(i==n)return 1;\n\n        if(dp[i][last][cnt]!=-1) return dp[i][last][cnt];\n\n        ll ans=0;\n\n        for(int x=1;x<=6;x++){\n            if(x==last){\n                if(cnt+1<=a[x-1]) // we can still include last\n                    ans+=f(i+1,last,cnt+1);\n            }\n            else{\n                ans+=f(i+1,x,1);\n            }\n        }\n\n        return dp[i][last][cnt]=ans%mod;\n    }\n\n    int dieSimulator(int _n, vector<int>& _a) {\n        a=_a; n=_n;\n        memset(dp,-1,sizeof(dp));\n        return f(0,0,0);\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C++']