HDU 1080 Human Gene Functions DP -
来源:互联网 发布:斯特拉文斯基 知乎 编辑:程序博客网 时间:2024/05/22 12:46
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1080
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;const int maxn=100+5;const int INF=0x3f3f3f3f;#define max3(a,b,c) max(a,max(b,c))char s1[maxn],s2[maxn];int d[maxn][maxn],len1,len2;//d[i][j]表示s1前i个和s2前j个匹配的最大值char str[]="ACGT-";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 inline Value(char a,char b){int p1=find(str,str+5,a)-str;int p2=find(str,str+5,b)-str;return score[p1][p2];}int solve(){memset(d,-INF,sizeof(d));d[0][0]=0;for(int i=1;i<=len1;i++){d[i][0]=d[i-1][0]+Value(s1[i],'-');d[0][i]=d[0][i-1]+Value(s2[i],'-');}for(int i=1;i<=len1;i++)for(int j=1;j<=len2;j++)d[i][j]=max3(d[i-1][j-1]+Value(s1[i],s2[j]),d[i-1][j]+Value(s1[i],'-'),d[i][j-1]+Value(s2[j],'-'));//s1[i]和s2[j] 匹配 s1[i]和'-'匹配 s2[j]和'-'匹配return d[len1][len2];}int main(int argc, char const *argv[]){int T; cin>>T;while(T--){scanf("%d %s",&len1,s1+1);scanf("%d %s",&len2,s2+1);cout<<solve()<<endl;}return 0;}
0 0
- hdu 1080 Human Gene Functions--DP
- hdu 1080 Human Gene Functions(dp)
- HDU 1080 Human Gene Functions dp
- hdu 1080 dp Human Gene Functions
- hdu 1080 Human Gene Functions (dp)
- HDU 1080 Human Gene Functions (DP)
- (DP)HDU 1080 Human Gene Functions
- hdu 1080 Human Gene Functions(LCS&DP)
- HDU - 1080 Human Gene Functions DP
- hdu 1080 Human Gene Functions dp
- 【DP|LCS】HDU-1080 Human Gene Functions
- hdu 1080 Human Gene Functions 线性dp
- 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
- 大数据系列修炼-Scala课程65
- 类图
- c++智能指针类实现
- Python 和 Asyncio 编写在线多人游戏(一)
- Oracle从零开始-Oracle数据库卸载
- HDU 1080 Human Gene Functions DP -
- leetcode解题报告:135. Candy
- 堆栈概念及区别
- 陶哲轩实分析 7.1 节习题试解
- Tomcat7优化配置
- 自学-ES6篇-简介
- 归并排序(从大到小)
- Photoshop制作木质音乐播放器主题UI图标
- nginx 安装配置