Given an integer N denoting the number of dices, the task is to find the probability of every possible value that can be obtained by throwing N dices together.
Input: N = 1
Explanation: On throwing a dice, the probability of all values from [1, 6] to appear at the top is 1/6 = 0.17
Input: N = 2
Explanation: The possible values of the sum of the two numbers that appear at the top on throwing two dices together ranges between [2, 12].
- Store the probabilies of all the 6 numbers that can appear on throwing 1 dices.
- Now, for N=2, the probability for all possible sums between [2, 12] is equal to the sum of product of the respective probability of the two numbers that add up to that sum. For example,
Probability of 4 on throwing 2 dices = (Probability of 1 ) * ( Probability of 3) + (Probability of 2) * ( Probability of 2) + (Probability of 3 ) * ( Probability of 1)
- Hence for N dices,
Probability of Sum S = (Probability of 1) * (Probability of S – 1 using N -1 dices) + (Probability of 2) * (Probability of S – 2 using N-1 dices) + ….. + (Probability of 6) * (Probability of S – 6 using N -1 dices)
- Hence, in order to solve the problem, we need to fill dp table from 2 to N using top-down approach using the relation:
dp[i][x] = dp[y] + dp[i-1][z] where x = y + z and i denotes the number of dices
- Display all the probabilities stored for N as the answer.
Below is the implementation of the above approach:
2 0.028 3 0.056 4 0.083 5 0.11 6 0.14 7 0.17 8 0.14 9 0.11 10 0.083 11 0.056 12 0.028
Time Complexity: O(N2)
Auxiliary Space: O(N2)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Probability of getting a sum on throwing 2 Dices N times
- Probability of obtaining Prime Numbers as product of values obtained by throwing N dices
- Maximum number of dots after throwing a dice N times
- All possible values of floor(N/K) for all values of K
- Conditional Probability and Independence - Probability | Class 12 Maths
- Number of ways to get a given sum with n number of m-faced dices
- Probability of getting at least K heads in N tosses of Coins
- Probability of getting two consecutive heads after choosing a random coin among two different types of coins
- Probability of getting more value in third dice throw
- Probability of getting more heads than tails when N biased coins are tossed
- Probability of getting K heads in N coin tosses
- Probability of getting a perfect square when a random number is chosen in a given range
- Probability of not getting two consecutive heads together in N tosses of coin
- Count of all possible values of X such that A % X = B
- Sum of values of all possible non-empty subsets of the given array
- Product of values of all possible non-empty subsets of given Array
- Find the probability of reaching all points after N moves from point N
- Minimum LCM and GCD possible among all possible sub-arrays
- Sort a String in decreasing order of values associated after removal of values smaller than X
- Sort first k values in ascending order and remaining n-k values in descending order
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.