NOI '06 P6 - The Magical Bag
View as PDFNational Olympiad in Informatics, China, 2006
Pòlya received a magical bag with symbols written on it that are difficult for humans to understand. Pòlya is in awe of the symbols. As he is painstakingly trying to contemplate their meaning, he discovered a magical model (known to later generations as the Pòlya model). To make the teaching of his model more vivid and interesting, he created a game for his students to play.
At the start of the game, the bag contains  balls of color 
,
 balls of color 
, …, 
 balls of color 
, where 
 
.
After the game has started, the following actions are strictly followed
at each step: Randomly draw a ball from the bag (there is equal
probability for drawing any ball). After Pòlya individually looks at the
color of the ball, he places the ball back into the bag, and then places
 balls of this color into the bag.
Let  represent the color of the ball drawn during the 
-th step
, then the process of the game will yield a color
sequence 
.
Regarding the  types of colored balls at the start of the game, Pòlya
has told all of the students the amount 
 of
each type. Then he asks his students: What is the probability of the
color sequence from a single game satisfying the following conditions?
where  and 
. In other
words, given 
,
you must determine the probability of the following event: "for all 
, 
, the ball drawn in
the 
-th draw has color 
."
Input Specification
The first line contains three positive integer  
, and 
 
.
The second line contains  integers 
 
representing the amount of each type of the 
 types of colored balls at the start of the game.
For the next  lines, each line contains a pair of positive integers
 
,
indicating that in step 
, a ball of color 
 is drawn.
Output Specification
Determine the answer in fraction form (it is clear that this probability
is a rational number). Output a single line in the format:
numerator/denominator. At the same time, output a reduced fraction
(where the numerator and denominator are relatively prime). For the
probability of , output 
0/1. For the probability of , output 
1/1.
Sample Input 1
2 3 1
1 1
1 1
2 2
3 1
Sample Output 1
1/12
Explanation of Sample 1
Initially, the amount of each of the two types of balls are .
The probability of drawing a ball with color 
 is 
.
Before the second draw, the amounts of the two types of balls are .
The probability of drawing a ball with color 
 is 
.
Before the third draw, the amounts of the two types of balls are .
The probability of drawing a ball with color 
 is 
.
Therefore, the total probability for all three draws is .
Sample Input 2
3 1 2
1 1 1
5 1
Sample Output 2
1/3
Problem translated to English by .
Comments