3

I've been faced with the following generalized problem in a programming problem.

Give a $N$ faced die (each face has an unique number in the range $[1, N]$), what's the probability of getting a value greater than or equal to $S$, after rolling the die $M$ times and summing all the obtained values?

$N, S, M$ are all given as input.

I've managed to solve this through a brute-force solution, by counting combinations that had a sum $\geq S$, but I'm more interested in an efficient mathematical approach. I've seen this post Probability of dice sum just greater than 100, but it didn't help me to understand how I should proceed for this particular problem.

Generating functions and coefficient identification seem to be too expensive regarding time complexity.

So, what would be an efficient mathematical algorithm for this?

  • What didn't you like about the approach with partitions? – Antoni Parellada Jan 07 '17 at 19:17
  • Well, to be honest I didn't quite understand it. Secondly, we can only construct partitions from a specific set (int this case, elements in the range $[1, N]$), so finding the number of partitions for a particular set is going to be quite expensive. The other computations will take their toll as well. This problem involves multiple queries, each of the form $N, S, M$, so I'd like to be able to answer each of them in reasonable time. – programmer101 Jan 07 '17 at 19:22

1 Answers1

1

One simple approach is to define a function $T(N,S,M)$ as the number of ways to get a given total. You have a recurrence $T(N,S,M)=\sum_{i=1}^NT(N,S-i,M-1)$ with starting value $T(N,0,0)=1$. Just compute starting with $M=1$ and going up. For each $M$, the maximum $S$ is $MN$ and you sum up $N$ terms to get it, so the complexity is $MN^2$ and getting all the way up to a maximum $M$ is $M^2N^2$

Ross Millikan
  • 374,822
  • this is just what I was looking for ! Can you expand a bit please? I'm thinkg of using a $3d$ table and storing the intermediate values in it and then proceeding with bottom-up approach. But I still don't quite get how to populate the table from your description. – programmer101 Jan 07 '17 at 23:07
  • You just need a 2D table. I have done it in Excel. You have values of the sum down one column and numbers of dice across the top. In the first column, for one die, you have $1$ in each sum from $1$ to $N$. Then each cell in the second column just sums the entries from the one above and to the left up to $N$ above. In the second column you should have $1,2,3\ldots,N-1,N,N-1,\ldots,3,2,1$ and so on. – Ross Millikan Jan 07 '17 at 23:17
  • I just found this answer which has more detail. – Ross Millikan Jan 08 '17 at 16:18
  • Thank you very much for your effort, Mr. Millikan ! – programmer101 Jan 08 '17 at 16:20