eolymp
bolt
Try our new interface for solving problems
Problems

Space Poker 3

Space Poker 3

Space poker. A legendary game, first version of which was introduced as far as in year 1284 of Alien era. Even nowadays its rules are known only to small group of professional players. Fortunately, the developers of the first program in the world playing space poker asked for your help. There are \textbf{N} extraterrestial players in space poker. At the beginning of the round, each player gets M cards (we call them \textit{hole cards}). Players don't know hole cards of their opponents. Then \textbf{K} \textit{community} cards are consecutively dealt face-up. So, community cards are known to all players. Player's \textit{hand} consists of his hole cards and all community cards --- \textbf{M+K} cards in total. There are no suits, cards differ only in their values. There are \textbf{13} different values: "\textbf{2}", "\textbf{3}", "\textbf{4}", …, "\textbf{9}", "\textbf{T}", "\textbf{J}", "\textbf{Q}", "\textbf{K}" and "\textbf{A}". The card deck is infinite, and the probability of the event that the next card will have a given value is equal to \textbf{1/13}. The combinations in space poker are represented in the form: \textbf{(v_1, …, v_L)}, where \textbf{L} is the number of different values in the combination. The hand satisfies the combination \textbf{(v_1, …, v_L)} in case it contains \textbf{v_1}cards of one value, \textbf{v_2} cards of another value, …, \textbf{v_L} cards of \textbf{L}-th value. For example, combination \textbf{(2, 2)} is satisfied by hands "\textbf{2JA2A}" and "\textbf{22233}". Combination \textbf{(2, 3)} is satisfied by hand "\textbf{KQKQKQ}" but is not satisfied by hand "\textbf{AAAAAA}". All combinations have different strength. The winner of the round is a player whose hand satisfies the combination of the maximal strength among all combinations in hands of all players. If there is more than one such player, the round ends in a draw. Suppose you know the hole cards of the first player and partly dealt community cards. Calculate the probability the first player will be the only winner of this round. \InputFile The first line contains integers \textbf{N}, \textbf{M} and \textbf{K} separated by spaces (\textbf{2} ≤ \textbf{N}, \textbf{M} ≤ \textbf{10}; \textbf{1} ≤ \textbf{K} ≤ \textbf{5}). The second line contains \textbf{M} symbols --- hole cards of the first player. The third line contains at most K symbols --- dealt community cards. The fourth line contains integer \textbf{C} --- the number of combinations in space poker (\textbf{1} ≤ \textbf{C} ≤ \textbf{100}). The following \textbf{C} lines contain combinations in order of increasing strength. Each description has the form \textbf{L v_1 v_2 … v_L}. \textbf{L} and \textbf{v_i} are positive integers, sum of all \textbf{v_i} doesn't exceed \textbf{M+K}. \OutputFile Output the probability of winning for the first player with absolute error not exceeding \textbf{10^\{−5\}}.
Time limit 3 seconds
Memory limit 64 MiB
Input example #1
2 5 2
23456

1
1 2
Output example #1
0.0883526857
Author Alex Samsonov
Source Ural SU Contest. Petrozavodsk Summer Session, August 2008