#include<stdio.h>
int basepair_match(char B[], int s[][2], int n) {
int i, j, t, k, sp, len, len1, temp;
int stack[7][2];
int L[15][15], st[15][15];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
L[i][j] = 0; st[i][j] = -1;
}
}
for (k = 5; k <= n - 1; k++) {
for (i = 0; i < n - k; i++) {
j = i + k; len = 0; temp = i;
for (t = i; t < j - 4; t++) {
if ((B[t] == 'A' && B[j] == 'U') ||
(B[t] == 'U' && B[j] == 'A') ||
(B[t] == 'C' && B[j] == 'G') ||
(B[t] == 'G' && B[j] == 'C')
){
if (i == t) len1 = 1 + L[i + 1][j - 1];
else len1 = 1 + L[i][t - 1] + L[t + 1][j - 1];
if (len < len1) {
len = len1; temp = t;
}
}
}
if (L[i][j - 1] > len)
L[i][j] = L[i][j - 1];
else {
L[i][j] = len;
st[i][j] = temp;
}
}
}
sp = 0; k = 0;
stack[0][0] = 0; stack[0][1] = n - 1;
while (sp >= 0) {
i = stack[sp][0]; j = stack[sp][1]; sp = sp - 1;
while (L[i][j] > 0) {
if (st[i][j] == -1) j = j - 1;
else {
s[k][0] = st[i][j];
s[k++][1] = j;
if (st[i][j] - 1 - i > 4) {
sp = sp + 1; stack[sp][0] = i;
stack[sp][1] - st[i][j] - 1;
}
i = st[i][j] + 1;
j = j - 1;
}
}
}
return L[0][n - 1];
}
int main() {
int n = 15;
char B[15] = { 'A','C','A','U','G','A','U','G','G','C','C','A','U','G','U' };
int s[15][2];
int q = basepair_match(B, s, n);
printf("%d", q);
return 0;
}
RNA最大碱基配对
最新推荐文章于 2024-08-16 23:08:28 发布