hdoj1080 Human Gene Functions(DP解决LCS问题!)
来源:互联网 发布:mysql web报表 编辑:程序博客网 时间:2024/06/15 23:48
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1080
类似于求最长公共字串,在dp的初始化和状态转移方程的书写上有少许差别。
dp[i][j] = dp[i-1,j] + dist[s1[i],'-'];s1[i]对上'-'
dp[i][j] = dp[i,j-1] + dist['-',s2[j]];'-'对上s2[j]
dp[i][j] = dp[i-1,j-1] + dist[s1[i],s2[j]];s1[i]对上s2[j]
dp[i,j]=max( dp[i-1,j] + dist[s1[i],'-'], dp[i,j-1]+dist['-',s2[j]], dp[i-1,j-1]+dist[s1[i],s2[j]]);
有关LCS问题的讲解链接:http://blog.csdn.net/rrrfff/article/details/7523437
本题的另外讲解链接:http://blog.sina.com.cn/s/blog_93ced90c01016rjv.html
代码如下:
#include<stdio.h>#include<string>#include<iostream>using namespace std;int max3(int a,int b,int c){int x;x=(a>b)?a:b;x=(c>x)?c:x;return x;}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 dp[105][105];int a1[105],a2[105];int main(){char s1[105],s2[105];int t,i,j,l1,l2;scanf("%d",&t);while(t--){scanf("%d%s%d%s",&l1,s1+1,&l2,s2+1);for(i=1;i<=l1;i++){if(s1[i]=='A')a1[i]=0;if(s1[i]=='C')a1[i]=1;if(s1[i]=='G')a1[i]=2;if(s1[i]=='T')a1[i]=3;}for(i=1;i<=l2;i++){if(s2[i]=='A')a2[i]=0;if(s2[i]=='C')a2[i]=1;if(s2[i]=='G')a2[i]=2;if(s2[i]=='T')a2[i]=3;}memset(dp,0,sizeof(dp));for(i=0;i<=l1;i++)for(j=0;j<=l2;j++){if (i==0&&j==0) dp[i][j]=0; else if (j==0&&i>0) dp[i][j]=dp[i-1][j]+score[a1[i]][4]; else if (i==0&&j>0) dp[i][j]=dp[i][j-1]+score[4][a2[j]]; else dp[i][j] = max3(dp[i-1][j-1]+score[a1[i]][a2[j]],dp[i][j-1]+score[4][a2[j]],dp[i-1][j]+score[a1[i]][4]);}printf("%d\n",dp[l1][l2]);}return 0;}
阅读全文
0 0
- hdoj1080 Human Gene Functions(DP解决LCS问题!)
- hdoj1080 Human Gene Functions (DP,map)
- POJ 1080 Human Gene Functions DP(LCS)
- hdu 1080 Human Gene Functions(LCS&DP)
- poj1080--Human Gene Functions(dp:LCS变形)
- 【DP|LCS】HDU-1080 Human Gene Functions
- POJ 1080 Human Gene Functions(DP LCS)
- POJ 1080 Human Gene Functions(DP:LCS)
- Human Gene Functions--DP
- [DP_BASIC][LCS]Human Gene Functions
- POJ-1080-Human Gene Functions-LCS变体,动态规划,DP
- POJ 1080-Human Gene Functions(DP:LCS变型)
- poj 1080 Human Gene Functions (dp,LCS)
- POJ 1080:Human Gene Functions LCS经典DP
- POJ-1080- Human Gene Functions-DP-LCS变形
- POJ Human Gene Functions 1080 lcs 变形 DP
- poj 1080Human Gene Functions(dp lcs 变形)
- HDU 1080 Human Gene Functions LCS变形问题
- 概率图模型系列(更新至2017.11.15)
- linux中的并发基础知识
- 学习Linux命令(22)
- 导入工程时提示Error:Configuration with name ‘default’ not found.解决方法
- UE(虚幻)4 蓝图可视化编程 03 数组
- hdoj1080 Human Gene Functions(DP解决LCS问题!)
- 数据库主键ID生成
- http接口测试——Jmeter接口测试实例讲解
- linux基础命令
- dechex (dec_number)—把十进制数字dec_number转换为十六进制
- BlueZ5.45 D-Bus总线 GATT API 分析
- <jsp:include page=""/>和<%@include file=""%>-----JSP中两种页面引入方式的区别
- 第一次正式的网页制作
- 使用Aspera从EBI或NCBI下载基因组数据