Best explanation why 3 parameters are required
class Solution {***\npublic:\n    typedef long long ll;\n    const int mod = 1000000007;\n    ll dp[5001][7][16];\n    int rec(int n,int last,int freq,vector&v)
### class Solution {***\npublic:\n    typedef long long ll;\n    const int mod = 1000000007;\n    ll dp[5001][7][16];\n    int rec(int n,int last,int freq,vector<int>&v){\n        if(n==0)\n            return 1;\n        if(dp[n][last][freq]!=-1)\n            return dp[n][last][freq];\n        ll ans = 0;\n        for(int i=1;i<=6;i++){\n            if(i==last){\n                if(freq+1<=v[i-1])\n                    ans=(ans+rec(n-1,i,freq+1,v))%mod;\n            }\n            else{\n                ans=(ans+rec(n-1,i,1,v))%mod;\n            }\n        }\n        return dp[n][last][freq]=ans;\n    }\n    int dieSimulator(int n, vector<int>& v) {\n        memset(dp,-1,sizeof dp);\n        return rec(n,0,0,v);\n    }\n};\nIn this question we want number of ways to form any number of lenght n\nfirst thought that comes to mind is just keep track of n and the last number used\ni.e f(n,j) is sufficent to represent a dp state but this is wrong . \nexample 21 and 11 have the same length==2 and same last number ==1\nbut these two are different dp states because in the second case one has ocurred 2 times \nsimultaionsly where as in first case it has occured only once hence we have to keep track of number of times the last number has occured\nnow the question is how the dp states are overlapping \nthis can be understood by example\n121 and 131 --- in both the cases length of sequence is 3 and last number is 1 and its cotinous frequncy is also 1 hence this is ans overlapping subproblem\nhence just calculate for 121 and it will be the same for 131,141,151,161\n
[]