#P14860. [ICPC 2021 Yokohama R] Cancer DNA

[ICPC 2021 Yokohama R] Cancer DNA

题目描述

The Investigation Center for Potential Cancer (ICPC) found out patterns of a DNA sequence that cause cancer! We would like you to write a computer program that approximates the probability that a random DNA sequence matches one of the given patterns.

A DNA sequence can be represented by a string consisting of four letters, ‘A’, ‘G’, ‘C’, and ‘T’. A DNA pattern is a string over the same four letters plus ‘?’. We say that a DNA pattern matches a DNA sequence of the same length if each of the characters in the pattern is either ‘?’ or is the same as the character at the corresponding position in the DNA sequence. For example, a pattern “AC?” matches DNA sequences “ACA”, “ACG”, “ACC”, and “ACT”.

Your task is to write a program that, given a set of DNA patterns of the same length, computes the probability that a uniformly random DNA sequence of the same length matches any of the given patterns. A multiplicative error up to 5%5\% is permissible.

输入格式

The input consists of a single test case of the following format.

n mn\ m P1P_1 \vdots PmP_m

The first line of the input contains two positive integers nn and mm such that 1n1001 \leq n \leq 100 and 1m301 \leq m \leq 30 hold. The next mm lines contain mm patterns P1,,PmP_1, \dots, P_m. Each pattern PiP_i is a string of length nn over ‘A’, ‘G’, ‘C’, ‘T’, and ‘?’.

输出格式

Let SS be a DNA sequence of length nn chosen uniformly at random. Let ww be the probability that SS matches at least one of P1,,PmP_1, \dots, P_m. The output is a real number vv that approximates ww.

The output vv is judged to be correct if vv approximates ww within a multiplicative error of 5%5\%, i.e.,

0.95×wv1.05×w0.95 \times w \leq v \leq 1.05 \times w

vv should be represented either with or without exponent component. For example, 0.0450.045 can be represented as 4.5e24.5\text{e}-2 or 0.0450.045.

3 1
AC?
0.0625
6 2
AC??A?
A??A?T
0.0302734375
30 1
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
8.673617379884035e-19

提示

In the first sample, there are 434^3 DNA sequences of length 3. There are 4 DNA sequences, “ACA”, “ACG”, “ACC”, and “ACT”, that match the pattern “AC?”. Thus, the probability is 4/43=0.06254/4^3 = 0.0625. Any real number between 0.0593750.059375 and 0.0656250.065625 is accepted as a correct output.

As in the third sample, the probability can be a small real number. Note that “0” is not a correct output, as 00 is less than 95%95\% of the precise probability.