CarrotBoxes
SRM 495 · 2010-11-01 · by rng_58
Problem Statement
Hanako wants to find the empty box without opening it. Fortunately, she has some clues. Some of the boxes contain information about the content of other boxes, and she knows which boxes contain such information. You are given a
Return the probability that she can find the empty box without opening it, assuming she behaves optimally.
Constraints
- information will contain between 1 and 50 elements, inclusive.
- Each element of information will contain exactly N characters, where N is the number of elements of information.
- The i-th character of the i-th element of information will be 'Y'.
- Each character in information will be 'Y' or 'N'.
Statement by TopCoder, Inc. — view the original on the archive.
{"YYYYY",
"NYNNN",
"NNYNN",
"NNNYN",
"NNNNY"}
Returns: 0.8
The optimal strategy is opening box 0 first. If box 0 contains carrots, she can find the empty box without opening it because box 0 contains information about all boxes. It happens with probability 0.8.
{"YNNNN",
"NYNNN",
"NNYNN",
"NNNYN",
"NNNNY"}
Returns: 0.2
No box contains information about other boxes, so she can find the empty box without opening it only when she opens all other boxes. It happens with probability 0.2.
{"Y"}
Returns: 1.0
Since there is only one box, she knows that the only box is empty.
{"YNNNN",
"YYNNN",
"YNYNN",
"NNNYY",
"NNNYY"}
Returns: 0.6
{"YYYNNNYN",
"NYNNNNYN",
"NNYNNNNN",
"NYNYNNNN",
"YNNNYNNY",
"NNYNNYNN",
"NNNNYNYN",
"NNYNNNNY"}
Returns: 0.875
Submissions are judged against all 139 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CarrotBoxes with a public method double theProbability(vector<string> information) · 139 test cases · 2 s / 256 MB per case