This is an iterative solution to this problem. Let's take 4 digit numbers involving 9 first, and then 8,7,6 etc. and find the combinations that sums upto $12$. After selecting a digit, next three digits are selected which are less than or equal to the selected one, to avoid repetition.
Numbers involving $9$ : The largest number we can involve in this case is $3$. After selecting $3$, a forced selection of two zeros remain. So we have $9,3,0,0$ selected. The possible combinations with these digits is given by $\frac{2*3*2*1}{2!}$, because we can not have $0$ in the $first$ position, and also $0$ is repeated $2$ times. In general, we can say,
the number of ways of arranging these digits is $ = \frac{(number\space of\space digits\space other\space than\space 0) * 3 * 2 * 1}{(no.\space of\space repetitions)!}$.
examples, if the digits selected are of the form
$x\space y\space z\space p\space$, then $\frac{4*3*2*1}{0!} = 24$
$x\space y\space z\space 0\space$, then $\frac{3*3*2*1}{0!} = 18$
$x\space x\space y\space z\space$, then $\frac{4*3*2*1}{2!} = 12$
$x\space x\space y\space 0\space$, then $\frac{3*3*2*1}{2!} = 9$
$x\space y\space 0\space 0\space$, then $\frac{2*3*2*1}{2!} = 6$
$x\space x\space x\space y\space$, then $\frac{4*3*2*1}{3!} = 4$
$x\space x\space 0\space 0\space$, then $\frac{2*3*2*1}{2!.2!} = 3$
$x\space x\space x\space 0\space$, then $\frac{3*3*2*1}{3!} = 3$
$x\space x\space x\space x\space$, then $\frac{4*3*2*1}{4!} = 1$ Combinations possible.
In this way we can calculate all possible numbers involving 9, and hence 9 doesn't have to be considered again. Let's complete the table then and sum it up to get the answer.
Selected
Digit
|
Possible
Selection(s)
for $sum=12$
|
Form
|
Number of
Combinations
Possible
|
$9$ |
3,0,0 |
x y 0 0 |
6 |
$9$ |
2,1,0 |
x y z 0 |
18 |
$9$ |
1,1,1 |
x x x y |
4 |
|
|
$Total$ |
$28$ ways |
$8$ |
4,0,0 |
x y 0 0 |
6 |
$8$ |
3,1,0 |
x y z 0 |
18 |
$8$ |
2,2,0 |
x x y 0 |
9 |
$8$ |
2,1,1 |
x x y z |
12 |
|
|
$Total$ |
$42$ ways |
$7$ |
5,0,0 |
x y 0 0 |
6 |
$7$ |
4,1,0 |
x y z 0 |
18 |
$7$ |
3,2,0 |
x y z 0 |
18 |
$7$ |
3,1,1 |
x x y z |
12 |
$7$ |
2,2,1 |
x x y z |
12 |
|
|
$Total$ |
$66$ ways |
$6$ |
6,0,0 |
x x 0 0 |
3 |
$6$ |
5,1,0 |
x y z 0 |
18 |
$6$ |
4,2,0 |
x y z 0 |
18 |
$6$ |
4,1,1 |
x x y z |
12 |
$6$ |
3,3,0 |
x x y 0 |
9 |
$6$ |
3,2,1 |
x y z p |
24 |
$6$ |
2,2,2 |
x x x y |
4 |
|
|
$Total$ |
$88$ ways |
$5$ |
5,2,0 |
x x y 0 |
9 |
$5$ |
5,1,1 |
x x y y |
6 |
$5$ |
4,3,0 |
x y z 0 |
18 |
$5$ |
4,2,1 |
x y z p |
24 |
$5$ |
3,3,1 |
x x y z |
12 |
$5$ |
3,2,2 |
x x y z |
12 |
|
|
$Total$ |
$81$ ways |
$4$ |
4,4,0 |
x x x 0 |
3 |
$4$ |
4,3,1 |
x x y z |
12 |
$4$ |
4,2,2 |
x x y y |
6 |
$4$ |
3,3,2 |
x x y z |
12 |
|
|
$Total$ |
$33$ ways |
$3$ |
3,3,3 |
x x x x |
1 |
|
|
$Total$ |
$1$ way |
So, the sum of all combinations is given by,
$28+42+66+88+81+33+1 = 342$.