TheGameDAG
TCO13 Semifinal 1 · 2013-02-19 · by gojira_tc
Problem Statement
Manao is the alpha-tester of this game. The DAG of the game was generated uniformly at random from the set of all DAGs with N vertices, and then Manao played the game and completed the missions in the order given in the
Manao wonders what was the DAG of the game he played. Given two vertices A and B, compute the probability that the edge (A, B) was present in the game's DAG.
Notes
- The returned value must have an absolute or relative error less than 1e-9.
Constraints
- P will contain between 2 and 9 elements, inclusive.
- P will contain each number from 1 to N exactly once, where N is the number of elements in P.
- A will be between 1 and the number of elements in P, inclusive.
- B will be between 1 and the number of elements in P, inclusive.
- A and B will be distinct.
{2, 1}
2
1
Returns: 0.6666666666666666
There are three DAGs composed of 2 vertices: an empty DAG, a DAG with arc 1->2 and a DAG with arc 2->1. For the empty DAG, Manao would complete mission 2 before mission 1 with probability 0.5. For the DAG with arc 1->2, he could not complete mission 2 before mission 1. For the DAG with arc 2->1, Manao would complete missions in the given order with probability 1.0. Thus, the arc 2->1 was present in the DAG of Manao's game with probability 1.0 / (0.5 + 1.0) = 0.(6).
{1, 2, 3}
3
1
Returns: 0.0
The DAG cannot contain the arc 3->1, because mission 1 was finished before mission 3.
{1, 2, 3}
1
3
Returns: 0.54
{1, 4, 3, 6, 5, 2}
3
5
Returns: 0.5569267034827158
{2,1}
2
1
Returns: 0.6666666666666666
Submissions are judged against all 57 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TheGameDAG with a public method double getProbability(vector<int> P, int A, int B) · 57 test cases · 2 s / 256 MB per case