HDU 1080 Human Gene Functions
2013-04-10 22:13
337 查看
最长公共子序列的变形题,算法导论公共子序列后的练习题有题是类似的
注意在公共子序列中要判断a[i]和b[j]相等,而此题是考虑相似,不要求相等
注意在公共子序列中要判断a[i]和b[j]相等,而此题是考虑相似,不要求相等
#include <iostream> #include <vector> #include <algorithm> #include <cstdio> #include <cstring> #include <string> #include <map> #define MAX 100 + 5 using namespace std; //dp[i][j]表示字符串a以a[i]结尾,字符串b以b[j]结尾的最大相似度 int dp[MAX][MAX]; int score[5][5]={ {5,-1,-2,-1,-3}, {-1,5,-3,-2,-4}, {-2,-3,5,-2,-2}, {-1,-2,-2,5,-1}, {-3,-4,-2,-1,0} }; int main(){ map<char,int> table; table['A'] = 0;table['C'] = 1;table['G'] = 2; table['T'] = 3;table['-'] = 4; int T; cin >> T; while(T--){ int na,nb; string stra,strb; cin >> na>>stra >> nb>>strb; memset(dp,0,sizeof(dp)); //注意边界条件 for(int i = 1; i <= na; i ++ ) dp[i][0] = dp[i-1][0] + score[ table[ stra[i-1] ] ][ table[ '-' ] ]; for(int i = 1; i <= nb; i ++ ) dp[0][i] = dp[0][i-1] + score[ table['-'] ][ table[ strb[i-1] ] ]; for(int i = 1 ; i <= na; i ++ ){ for(int j = 1; j <= nb; j ++){ dp[i][j]= max(dp[i- 1 ][j -1 ] + score[ table[ stra[i-1] ] ][ table[ strb[j-1] ]], max(dp[i- 1 ][j] + score[ table[ stra[i-1] ]][ table[ '-' ]], dp[i][j-1] + score[ table[ '-' ]][ table[ strb[j-1] ]]) ); } } cout<<dp[na][nb]<<endl; } return 0; }
相关文章推荐
- hdu 1080 Human Gene Functions
- 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
- HDU1080——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(dp)
- hdu 1080 Human Gene Functions
- HDU 1080 Human Gene Functions (DP,最长公共子序列)
- HDU 1080 Human Gene Functions(带权值的最长公共子序列)
- HDU 1080 Human Gene Functions(变形的LCS)