HDU1080——Human Gene Functions
2011-12-02 19:58
337 查看
题目大意:基因工程,给你两段基因序列,给定任意两个字符间的相似度,可以根据需要插入减号(-)与字符匹配,求这两段基因序列的最大相似度。
算法分析:一道dp题,类似于求两个字符串的编辑距离,主要找到状态转移方程:f[i][j] = Max(f[i][j - 1] + Match('-', s2[j]), f[i - 1][j] + Match('-', s1[i]), f[i - 1][j - 1] + Match(s1[i], s2[j]));
View Code
算法分析:一道dp题,类似于求两个字符串的编辑距离,主要找到状态转移方程:f[i][j] = Max(f[i][j - 1] + Match('-', s2[j]), f[i - 1][j] + Match('-', s1[i]), f[i - 1][j - 1] + Match(s1[i], s2[j]));
View Code
/*dp题状态转移方程: f[i][j] = Max(f[i][j - 1] + Match('-', s2[j]), f[i - 1][j] + Match('-', s1[i]), f[i - 1][j - 1] + Match(s1[i], s2[j])); f[i][j]表示第一个字符串的前i个字符和第二个字符串的前j个字符的最大相似度Match(a, b) 表示字符a与字符b的相似度, 程序中预处理,存入数组mat[][]中*/ #include<stdio.h> #define N 102 int Max(int a, int b) { return a > b ? a : b; } int main() { int T, i, j, len1, len2; char s1 , s2 ; int f , mat ; mat['A']['A'] = mat['C']['C'] = mat['G']['G'] = mat['T']['T'] = 5; mat['A']['C'] = mat['C']['A'] = mat['A']['T'] = mat['T']['A'] = mat['-']['T'] = -1; mat['A']['G'] = mat['G']['A'] = mat['C']['T'] = mat['T']['C'] = mat['G']['T'] = mat['T']['G'] = mat['-']['G'] = -2; mat['-']['A'] = mat['C']['G'] = mat['G']['C'] = -3; mat['-']['C'] = -4; scanf("%d", &T); while (T--) { scanf("%d%s%d%s", &len1, s1, &len2, s2); f[0][0] = 0; for (i = 1; i <= len1; i++) { f[i][0] = f[i - 1][0] + mat['-'][s1[i - 1]]; } for (j = 1; j <= len2; j++) { f[0][j] = f[0][j - 1] + mat['-'][s2[j - 1]]; } for (i = 1; i <= len1; i++) { for (j = 1; j <= len2; j++) { f[i][j] = Max(f[i][j - 1] + mat['-'][s2[j - 1]], Max(f[i - 1][j] + mat['-'][s1[i - 1]], f[i - 1][j - 1] + mat[s1[i - 1]][s2[j - 1]])); } } printf("%d\n", f[len1][len2]); } return 0; }
相关文章推荐
- hdu 1080 Human Gene Functions
- Hdu 1080 Human Gene Functions(DP)
- hdu 1080 Human Gene Functions (LCS变形)
- hdu 1080 Human Gene Functions (LCS的变形)
- HDU 1080 Human Gene Functions(LCS变形)
- hdu 1080 Human Gene Functions 线性dp
- hdu 1080 Human Gene Functions (dp)
- HDU 1080 Human Gene Functions (DP)
- hdu 1080 Human Gene Functions( 类似最长公共子序列)
- HDU 1080 Human Gene Functions(最长公共子序列变形)
- hdu 1080 Human Gene Functions(dp)
- 【Hdu】1080 Human Gene Functions
- hdu 1080 Human Gene Functions(dp)
- hdu 1080 Human Gene Functions
- hdu 1080 Human Gene Functions(带权值的最大子序列)
- hdu 1080 Human Gene Functions (编辑距离问题)
- hdu 1080 Human Gene Functions
- HDU 1080 Human Gene Functions (DP,最长公共子序列)
- HDU 1080 Human Gene Functions(带权值的最长公共子序列)
- HDU 1080 Human Gene Functions(变形的LCS)