QOJ.ac

QOJ

実行時間制限: 10 s メモリ制限: 1024 MB 満点: 100
統計

潜在癌症研究中心(ICPC)发现了导致癌症的 DNA 序列模式!我们希望你编写一个计算机程序,来近似计算一个随机 DNA 序列匹配到给定模式之一的概率。

DNA 序列可以用由四个字母 'A'、'G'、'C' 和 'T' 组成的字符串来表示。DNA 模式是一个由上述四个字母加上 '?' 组成的字符串。如果 DNA 模式中每个字符要么是 '?',要么与 DNA 序列对应位置的字符相同,我们就说该 DNA 模式与该长度相同的 DNA 序列匹配。例如,模式 "AC?" 匹配 DNA 序列 "ACA"、"ACG"、"ACC" 和 "ACT"。

你的任务是编写一个程序,给定一组长度相同的 DNA 模式,计算一个长度相同的均匀随机 DNA 序列匹配到其中任意一个给定模式的概率。允许最多 5% 的乘法误差。

输入格式

输入包含单个测试用例,格式如下:

$n$ $m$ $P_1$ $\vdots$ $P_m$

第一行包含两个正整数 $n$ 和 $m$,满足 $1 \le n \le 100$ 且 $1 \le m \le 30$。接下来的 $m$ 行包含 $m$ 个模式 $P_1, \dots, P_m$。每个模式 $P_i$ 是一个长度为 $n$ 的字符串,由 'A'、'G'、'C'、'T' 和 '?' 组成。

输出格式

设 $S$ 为一个长度为 $n$ 的均匀随机选择的 DNA 序列。设 $w$ 为 $S$ 匹配到 $P_1, \dots, P_m$ 中至少一个模式的概率。输出一个近似 $w$ 的实数 $v$。

如果 $v$ 在 $w$ 的 5% 乘法误差范围内,则输出 $v$ 被判定为正确,即: $0.95 \times w \le v \le 1.05 \times w$

$v$ 可以用科学计数法或普通小数表示。例如,0.045 可以表示为 4.5e-2 或 0.045。

样例

输入 1

3 1
AC?

输出 1

0.0625

输入 2

6 2
AC??A?
A??A?T

输出 2

0.0302734375

输入 3

30 1
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

输出 3

8.673617379884035e-19

说明

在第一个样例中,有 $4^3$ 个长度为 3 的 DNA 序列。有 4 个 DNA 序列 "ACA"、"ACG"、"ACC" 和 "ACT" 匹配模式 "AC?"。因此,概率为 $4/4^3 = 0.0625$。 任何介于 0.059375 和 0.065625 之间的实数都被接受为正确输出。

如第三个样例所示,概率可能是一个很小的实数。注意 "0" 不是一个正确的输出,因为 0 小于精确概率的 95%。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.