CF222E.Decoding Genome
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is k.
The needs of gene research required information about the quantity of correct n-long chains of the Martian DNA. Your task is to write a program that will calculate this value.
最近,一次前往火星的绝密任务已经完成。结果,科学家们成功获取了一些关于火星DNA的信息。现在我们已知,任何火星DNA最多包含 m 种不同的核苷酸,编号从 1 到 m。火星DNA的特殊性质导致某些核苷酸对不能在该链中连续出现。例如,若核苷酸 1 与核苷酸 2 不能在火星DNA中连续出现,则核苷酸序列 [1,2] 不是合法的火星DNA序列,但核苷酸序列 [2,1] 可能是合法的(前提是不存在相应的限制)。不能在DNA链中连续出现的核苷酸对的总数为 k。
基因研究的需求要求获得长度为 n 的合法火星DNA序列的数量信息。你的任务是编写一个程序来计算该数值。
输入格式
The first line contains three space-separated integers n, m, k (1 ≤ n ≤ 1015, 1 ≤ m ≤ 52, 0 ≤ k ≤ _m_2).
Next k lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide.
The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z").
It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than m. Note that order is important in nucleotide pairs.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
第一行包含三个以空格分隔的整数 n、m、k(1≤n≤1015,1≤m≤52,0≤k≤m2)。
接下来的 k 行每行包含两个无空格分隔的字符,表示一个被禁止的核苷酸对。第一个字符表示该禁止对中的第一个核苷酸,第二个字符表示第二个核苷酸。
编号为 1 至 26 的核苷酸用英文字母 "a" 至 "z" 表示(即 1 对应 "a",2 对应 "b",……,26 对应 "z");编号为 27 至 52 的核苷酸用英文字母 "A" 至 "Z" 表示(即 27 对应 "A",28 对应 "B",……,52 对应 "Z")。
保证输入中每个被禁止的核苷酸对至多出现一次。保证所有被禁止核苷酸对中涉及的核苷酸编号均不超过 m。注意:核苷酸对中字符的顺序是重要的。
请注意:在 C++ 中读写 64 位整数时,请勿使用 %lld 格式说明符。推荐使用 cin/cout 流,或使用 %I64d 格式说明符。
输出格式
Print a single integer — the sought number modulo 1000000007 (109 + 7).
输出一个整数——所求的数对 1000000007(即 109+7)取模的结果。
输入输出样例
输入#1
3 3 2 ab ba
输出#1
17
输入#2
3 3 0
输出#2
27
输入#3
2 1 1 aa
输出#3
0
说明/提示
In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs.
In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively.
在第二个测试用例中,所有可能的三核苷酸 DNA 均被允许。每个核苷酸可以取三个值之一,因此总共有 27 种不同的三核苷酸 DNA。
在第三个测试样例中,我们无法构造任何长度为二的 DNA——唯一可能的核苷酸 “a” 不能连续出现两次。
输入解题思路,AI测评打分。不知道怎么写?