아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Cancer DNA

시간 제한10초메모리 제한1024 MB

요약
길이 n인 DNA 패턴 30개 이하가 주어질 때, 무작위 DNA 서열이 그중 하나 이상과 일치할 확률을 계산한다.
난이도

보통10점 중 7점

유형
동적 계획법, 확률, 문자열
정답자
아직 제출이 없습니다

문제

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% is permissible.

입력

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

\begin{align\*}& n \\, m \\\ & P\_1 \\\ & \vdots \\\ & P\_m\end{align\*}

The first line of the input contains two positive integers nn and mm such that 1≤n≤1001 ≤ n ≤ 100 and 1≤m≤301 ≤ m ≤ 30 hold. The next mm lines contain mm patterns P_1P\_1, …\dots, P_mP\_m. Each pattern P_iP\_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 P_1P\_1, …\dots, and P_mP\_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%, i.e.,

0.95×w≤v≤1.05×w0.95 × w ≤ v ≤ 1.05 × w.

vv should be represented either with or without exponent component. For example, 0.0450.045 can be represented as 4.5e-2 or 0.045.

힌트

In the first sample, there are 434^3 DNA sequences of length 33. There are 44 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% of the precise probability.

예제3

  1. 예제 1

    입력
    3 1
    AC?
    
    예상 출력
    0.0625
    
  2. 예제 2

    입력
    6 2
    AC??A?
    A??A?T
    
    예상 출력
    0.0302734375
    
  3. 예제 3

    입력
    30 1
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    
    예상 출력
    8.673617379884035e-19