I've been trying to do a Dynamic Programming assignment for university but I had no success so far.
(我一直在尝试大学的动态编程任务,但到目前为止我还没有成功。)
The problem:
(问题:)
Given a DNA string and a list of mutation locations (for exemple, pieces 0 and 2 are mutations), find the longest palindromic sub-sequence that contains the most mutations on it.
(给定一个DNA字符串和一个突变位置列表(例如,片段0和2是突变),找到包含其上最多突变的最长回文子序列。)
Input: a string S with 0 to 2000 chars;
(输入:0到2000个字符的字符串S;)
an integer N such that 0<=N<=|S| (整数N,使得0 <= N <= | S |)
and N positions (numbers from 0 to |S|) of mutations. (和N个位置(数字从0到| S |)。)
Output: an integer representing the size of the longest palindromic sub-sequence containing the maximum number of mutations.
(输出:一个整数,代表最长回文子序列的大小,其中包含最大突变数。)
Examples:
(例子:)
Input: CAGACAT 0
(输入:CAGACAT 0)
Output: 5
(输出:5)
Input: GATTACA 1 0
(输入:GATTACA 1 0)
Output: 1
(输出1)
Input: GATTACA 3 0 4 5
(输入:GATTACA 3 0 4 5)
Output: 3
(输出3)
Input: TATACTATA 2 4 8
(输入:TATACTATA 2 4 8)
Output: 7
(输出:7)
We have to code it in C, but what I really need are ideas, any language or pseudo-code is good to me.
(我们必须用C编写代码,但是我真正需要的是想法,任何语言或伪代码对我都很好。)
My code to find the LPS (in C)
(我找到LPS的代码(在C中))
int find_lps(char *input)
{
int len = strlen(input), i, cur_len;
int c[len][len];
for (i = 0; i < len; i++)
c[i][i] = 1;
for (cur_len = 1; cur_len < len; cur_len++) {
for (i = 0; i < len - cur_len; i++) {
int j = i + cur_len;
if (input[i] == input[j]) {
c[i][j] = c[i + 1][j - 1] + 2;
} else {
c[i][j] = max(c[i + 1][j], c[i][j - 1]);
}
}
}
return c[0][len - 1];
}
What I tried to do for the mutations:
(我试图为突变做些什么:)
1- Creating an array of places where the LPS is changed.
(1-创建更改LPS的位置的数组。)
That doesn't work, and really, I have no idea of what to do. (那是行不通的,实际上,我不知道该怎么办。)
More details about the problem: In a situation where you have n palindromic subsequences, both of them with the same size of mutations inside, I need the longest of them.
(有关该问题的更多详细信息:在您有n个回文序列的情况下,这两个子序列内部都有相同大小的突变,我需要它们中最长的一个。)
Given that you have n palindromic subsequences with X mutations, (we have M mutations), I need the longest palindromic subsequence of X mutations, considering you don't have a palindromic subsequence with M mutations. (假设您有n个具有X突变的回文子序列(我们有M个突变),考虑到您没有具有M突变的回文子序列,我需要最长的X突变的回文子序列。)
If you do, then you should choose the other subsequence, even if it's shorter. (如果这样做,则应该选择另一个子序列,即使它更短。)
So, first criteria: most mutations in a palindromic subsequence. (因此,第一个标准:回文子序列中的大多数突变。)
If we have the same amount, then the longest of the subsequences. (如果我们有相同的数量,那么最长的子序列。)
Any help is appreciated, thank you.
(任何帮助表示赞赏,谢谢。)
ask by c-orlando translate from so