Method with Queue
The DP based method would require a matrix, which can actually be replaced by a queue.\n\n\n\tint helper(int n, const vector&A){\n        const int c = 1e9+7;\n
The DP based method would require a matrix, which can actually be replaced by a queue.\n\n\n\tint helper(int n, const vector<int>&A){\n        const int c = 1e9+7;\n        int res = 0;\n        vector<queue<int>> vq(6, queue<int>());\n        vector<int> sum(6,1);\n        for(int j = 0; j < 6; j++)\n            vq[j].push(1);\n        for(int i = 2; i <= n; i++){\n            int t = 0;\n            for(int k = 0; k < 6; k++)\n                t += sum[k], t %= c;\n            for(int j = 0; j < 6; j++){\n                int t2 = (t+c-sum[j])%c;\n                vq[j].push(t2);\n                sum[j] += t2;\n                sum[j] %= c;\n                if(vq[j].size()>A[j])\n                    sum[j] += c-vq[j].front(), vq[j].pop();\n                sum[j] %= c;\n            }\n        }\n        for(int j = 0; j < 6; j++)\n            res += sum[j], res %= c;\n        return res;\n    }
[]