Conditional
SRM 304 · 2006-05-27 · by dgoodman
Problem Statement
Our goal is to solve a generalized version of this problem in which we roll nDice identical dice, each with sides labelled 1,2,...,maxSide. We want to know the probability that the sum of the dice is greater than or equal to theSum given that at least one of the dice shows the value v. Create a class Conditional that contains a method probability that is given nDice,maxSide, v, and theSum and that returns the desired conditional probability.
Notes
- The returned value must be accurate to within a relative or absolute value of 1E-9.
Constraints
- nDice and maxSide will be between 1 and 50, inclusive.
- v will be between 1 and maxSide, inclusive.
- theSum will be between 1 and maxSide*nDice, inclusive.
2 6 6 12 Returns: 0.09090909090909091
This is the example above whose answer is 1/11. (Of course, the sum cannot be greater than 12.)
2 6 6 6 Returns: 1.0
Given that at least one of the dice shows a 6 the sum of the 2 dice must be at least 7.
1 9 3 3 Returns: 1.0
2 3 2 4 Returns: 0.6
Two 3-sided (!) dice with at least one 2 showing: 12 22 32 21 23 are the 5 possible equally likely results, and 3 of the 5 have a sum greater than or equal to 4.
50 50 50 1 Returns: 0.9999999999999967
Submissions are judged against all 109 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Conditional with a public method double probability(int nDice, int maxSide, int v, int theSum) · 109 test cases · 2 s / 256 MB per case