Soccer
InterviewTime limit2sMemory limit128 MB
Compute probability distribution of final scores after up to T seconds of a stochastic soccer simulation with passing, stealing, shooting, and absorbing states.
- Level
Medium5 of 10
- Topics
- Probability, Dynamic programming, Simulation, Combinatorics
- Solved
- No attempts yet
Problem
players are split into two teams playing soccer. Every player wears their own team's uniform, and the shirt numbers run from to on each team.
Each player knows their own shooting accuracy , the set of teammates they can pass to, and the set of opposing players who can steal the ball from them.
Once a player gets the ball, exactly one of the following three events happens during the next second:
- Pass to one of the teammates in .
- Have the ball stolen by one of the opposing players in .
- Take a shot at the goal.
When a player shoots, they score with probability equal to their accuracy . After the shot, regardless of the outcome, player number of the opposing team receives the ball.
The three events occur with probability ratio , and previous events do not affect later ones. (Here denotes the size of set .) For a pass or a steal, every player in the relevant set is equally likely to be chosen. The time during which no player holds the ball is negligibly short.
The match starts with player of the first team holding the ball. The match ends as soon as some team scores goals, or once seconds have elapsed since the start. For every possible final score, compute the probability that the match ends with that score.
The figure below illustrates one example input.

Input
The first line contains , , and . (, , )
The next lines describe the players of the first team in order from number , followed by lines describing the players of the second team in order from number .
Each player's description begins with that player's accuracy (), followed by the size of set and the size of set (, ). Then come integers separated by spaces: the first are the shirt numbers of the teammates in , and the remaining are the shirt numbers of the opposing players in . A player's own number is never contained in .
Output
There are exactly theoretically possible final scores. For each of them, print the probability that the match ends with that score as an irreducible fraction in the form numerator/denominator, one per line. Print 0/1 when the probability is and 1/1 when it is .
Print the scores ordered by the first team's score ascending, breaking ties by the second team's score ascending.