DNA Deletions and Protein Count
Time limit2sMemory limit128 MB
Count, modulo 1e9+7, the distinct proteins obtainable by deleting some nucleotides from a DNA string and translating the remaining codons via a given table.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, String matching, String
- Solved
- No attempts yet
Problem
A DNA string consists of the nucleotides A, C, G, and T. Some DNA strings can be converted into a protein, which is a nonempty sequence of amino acids. The conversion works as follows.
- Split the string from left to right into non-overlapping groups of 3 characters. Each group is called a codon. If 1 or 2 nucleotides remain at the end, ignore them. For example, the DNA string
ACCTGTACGproduces the codonsACC,TGT, andACGin that order, whileACCTGTACproduces onlyACCandTGT, ignoring the finalAC. - Using the given codon conversion table, replace each codon from left to right by its corresponding amino acid. If any codon is not in the table, the string cannot be converted into a protein. For example, if
ACCmaps tothr,TGTmaps tocys, andACGmaps tothr, thenACCTGTACGis converted intothr cys thr.
A deletion removes one or more nucleotides from a DNA string. The remaining nucleotides keep their relative order. For example, after a deletion, ACTG could become ACG or CG, among other strings.
Given a DNA string and a codon conversion table, compute how many distinct proteins can be obtained after applying zero or more deletions.
Input
The first line contains the DNA string. Its length is at most 2,500.
The second line contains M, the number of codons in the codon conversion table. M is at most 50.
Each of the next M lines contains one table entry: a codon followed by an amino acid. A codon is a length-3 string made only of A, C, G, and T. An amino acid is a nonempty string of length at most 20 consisting of uppercase or lowercase English letters. No codon appears more than once in the table.
Output
Print one line containing the number of distinct obtainable proteins modulo 1,000,000,007.