Poj 1080 Human Gene Functions
2012-01-19 14:16
260 查看
题目大意:已知ATCG四种不同的碱基之间的相似度。现在给出两个碱基序列,可以在两个串间插入‘-’即空白,求两串的最大相似度。
思路:有点类似于LCS,状态转移方程为dp[i][j]=getMax(dp[(i-1)][j-1]+table[str1[i]][str2[j]],dp[(i-1)][j]+table[str1[i]][4],dp[i][j-1]+table[4][str2[j]])。
#include <stdio.h> #include <string.h> #include <memory.h> int table[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 dp[105][105]; int str1[105]; int str2[105]; int m,n; int change(char c) { if (c=='A') return 0; else if (c=='C') return 1; else if (c=='G') return 2; else if (c=='T') return 3; else return 4; } int getMax(int a,int b,int c) { int temp; if (a>b) temp=a; else temp=b; if (c>temp) temp=c; return temp; } int solve_dp() { int i,j,ctr; dp[0][0]=0; for (i=1;i<=m;i++) dp[i][0]=dp[i-1][0]+table[str1[i]][4]; for (i=1;i<=n;i++) dp[0][i]=dp[0][i-1]+table[4][str2[i]]; for (i=1;i<=m;i++) { for (j=1;j<=n;j++) { dp[i][j]=getMax(dp[(i-1)][j-1]+table[str1[i]][str2[j]],dp[(i-1)][j]+table[str1[i]][4],dp[i][j-1]+table[4][str2[j]]); } } ctr=dp[m] ; return ctr; } int main() { int t,i,j; int result; char temp; scanf("%d",&t); while (t--) { scanf("%d",&m); getchar(); for (i=1;i<=m;i++) { scanf("%c",&temp); str1[i]=change(temp); } scanf("%d",&n); getchar(); for (i=1;i<=n;i++) { scanf("%c",&temp); str2[i]=change(temp); } result=solve_dp(); printf("%d\n",result); } return 0; }
相关文章推荐
- poj 1080 Human Gene Functions (dp,LCS)
- POJ 1080 Human Gene Functions
- POJ 1080 Human Gene Functions 【dp】
- POJ 1080 Human Gene Functions
- Human Gene Functions - POJ 1080 UVaLive 2344 dp
- POJ 1080 Human Gene Functions (类似LCS)
- poj 1080 Human Gene Functions
- POJ 1080 Human Gene Functions 【DP】
- poj 1080 Human Gene Functions 算简单DP
- poj 1080 Human Gene Functions_简单dp
- POJ - 1080 - Human Gene Functions (LCS的变形)
- POJ 1080 Human Gene Functions
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
- poj 1080 Human Gene Functions
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
- poj 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- POJ 1080 Human Gene Functions 笔记
- poj_1080 Human Gene Functions(dp)
- hdu 1080 Human Gene Functions