Editorial for APIO '08 P3 - DNA


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

First, we ignore the templates and only count the number of sequences of form-k.

Let A[i][k][α] denote the number of sequences of form-k of length i beginning with α. Note that if the second character β comes before α, possible sequences of form-k are those constructed by concatenating α with form-(k1) sequences beginning with β. On the other hand, if β is α or comes after α, we can concatenate α with any form-k sequence.

Thus, we have the following recurrence:

A[i][k][α]=βαA[i1][k][β]+β<αA[i1][k1][β]

This idea can be extended to count the number of sequences that also match the templates. Table A can be computed in time O(MK).

Given A, we can trace back the computation of A to find the required R-th gene sequence.


Comments

There are no comments at the moment.