loj#P3042. 「ZJOI2019」麻将
「ZJOI2019」麻将
Description
The translation of riichi terms comes from WRC and EMA
Kujo Karen loves playing Majsoul, so she makes out a problem about Majsoul. Wish you won't no longer love Majsoul because of this problem.
Today Karen decides to play Majsoul, but all her friends have gone to play Dota AutoChess and Karen have to play mahjong alone. She finds a special mahjong set. The mahjong set consists of ranks of tiles (ranked from to ), and each rank of tiles include 4 tiles (numbered from 1 to 4). In this problem, we DO NOT consider their suits.
A chow (shuntsu 順子) is three consecutive tiles (i.e. their ranks are , , respectively). A pung (kōtsu 刻子) is composed of three identical tiles. A group (mentsu 面子) is either a chow or pung (In this problem, we DO NOT consider kong). A pair (toitsu 対子) is composed of two identical tiles.
A player's hand (his/her 14 tiles) is a winning hand if it has four groups and a pair, or seven different pairs.
For example, these hands are winning hands:
And these are not:
Firstly, Karen draws tiles from the wall, and shuffle the remaining tiles. The shuffle is at random, i.e. all the permutations have equal probability to appear.
For a permutation , denote as a mahjong hand composed of Karen's prepared tiles and 's first tiles. the weight of is the smallest which can let exist a subset that is a winning hand. If you are familiar with mahjong, obviously the weight of equals to the minimum turns to complete a winning hand. Notice that when , always has a subset that is a winning hand, so the weight of is well-defined.
She lets you to calculate the expected value of the weight of in advance.
Input
The first line contains a single number .
Each of the next lines contains 2 numbers — the -th tile Karen draws is the -th tile of rank .
Output
Print a single number — the answer , i.e. if the answer's simplest fraction is , you should print .
9
1 1
1 2
1 3
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
9 2
9 3
1
Limits
Cases 1 and 2 satisfy .
Cases 3-5 satisfy .
Cases 6 and 7 satisfy .
Cases 8 and 9 satisfy $n \le 100, w_i = \large\lceil\normalsize \frac{i}{4} \large\rceil\normalsize, t_i = i \bmod 4 + 1$.
All test cases satisfy .