Suppose I have $\{1, 1\} \{2, 2, 2\} \{5\} \{10\}$ coins.
How many ways I can get 15 by adding coins?
If I use DP then it counts 7, because $\{1+2+2+10\} \{1+2+2+10\} \{1+2+2+10\} \{1+2+2+10\} \{1+2+2+10\} \{1+2+2+10\}$ and $\{10 + 5\}$. But actual result is $\{1+2+2+10\}$ and $\{10 + 5\}$. How do I solve efficiently?
Now I able to figure out the solution. I have to find integral solutions of equation $x+2y+5z+10m=15$ with constraints $x <= 2$, $y <= 3$, $z <= 1$ and $m <= 1$. Now how to do that?
This is a supplement to the already given answer showing that calculating the coefficient is not that cumbersome. We use the coefficient of operator $[x^n]$ to denote the coefficient of $x^n$ in a polynomial.
Comment:
In (1) we multiply out the terms with the highest powers which is convenient as we will see in step (3).
In (2) we use the linearity of the coefficient of operator and apply the rule $[x^{p-q}]A(x)=[x^p]x^qA(x)$.
In (3) we can skip $[x^{15}]$ and $[x^{10}]$ since they do not contribute as the highest power of $x$ is $8$.
In (4) we select the coefficient of $x^0$.
In (5) we select the coefficient of $x^5$.