A brutal approach (there are better ways) would be counting from
0
to
(m^n-1)
. At each iteration the counter represents a valid dice configuration and you can check if the sum of dices makes up
total
.
E.g.
Suppose you have two 6-ways dices (i.e.
n=2
,
m=6
) and
total = 5
.
Then you have to iterate from
0
to
6^2-1=35
counter dice-1 dice-0 sum
0 1 1 2
1 1 2 3
2 1 3 4
3 1 4 5 OK
4 1 5 6
5 1 6 7
6 2 1 3
7 2 2 4
8 2 3 5 OK
9 2 4 6
10 2 5 7
11 2 6 8
...........................
...........................
35 6 6 12