【POJ 1080】 Human Gene Functions
【POJ 1080】 Human Gene Functions
相似于最长公共子序列的做法
dp[i][j]表示 str1[i]相应str2[j]时的最大得分
转移方程为
dp[i][j]=max(dp[i-1][j-1]+score[str1[i]][str2[j]],
max(dp[i-1][j]+score[str1[i]][‘-‘],dp[i][j-1]+score[‘-‘][str2[j]]) )
注意初始化0下标就好
代码例如以下:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int dp[101][101];
char a[102],b[102];
int sc['Z'+1]['Z'+1];
int main()
{
int t,aa,bb,i,j;
scanf("%d",&t);
sc['A']['A'] = sc['C']['C'] = sc['G']['G'] = sc['T']['T'] = 5;
sc['A']['C'] = sc['C']['A'] = sc['A']['T'] = sc['T']['A'] = sc['T']['-'] = -1;
sc['G']['A'] = sc['A']['G'] = sc['C']['T'] = sc['T']['C'] = sc['G']['T'] = sc['T']['G'] = sc['G']['-'] = -2;
sc['A']['-'] = sc['C']['G'] = sc['G']['C'] = -3;
sc['C']['-'] = -4;
while(t--)
{
scanf("%d %s %d %s",&aa,a+1,&bb,b+1);
dp[0][0] = 0;
for(i = 1; i <= bb; ++i) dp[0][i] = sc[b[i]]['-'] + dp[0][i-1];
for(i = 1; i <= aa; ++i) dp[i][0] = sc[a[i]]['-'] + dp[i-1][0];
for(i = 1; i <= aa; ++i)
{
for(j = 1; j <= bb; ++j)
{
dp[i][j] = max(dp[i-1][j-1] + sc[a[i]][b[j]],max(dp[i-1][j] + sc[a[i]]['-'],dp[i][j-1] + sc[b[j]]['-']));
}
}
printf("%d\n",dp[aa][bb]);
}
return 0;
}
【POJ 1080】 Human Gene Functions的更多相关文章
- POJ 1080:Human Gene Functions LCS经典DP
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18007 Accepted: ...
- 【poj1080】 Human Gene Functions
http://poj.org/problem?id=1080 (题目链接) 题意 给出两个只包含字母ACGT的字符串s1.s2,可以在两个字符串中插入字符“-”,使得s1与s2的相似度最大. Solu ...
- 杭电1080 J - Human Gene Functions
题目大意: 两个字符串,可以再中间任何插入空格,然后让这两个串匹配,字符与字符之间的匹配有各自的分数,求最大分数 最长公共子序列模型. dp[i][j]表示当考虑吧串1的第i个字符和串2的第j个字符时 ...
- poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17805 Accepted: ...
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- 【POJ 2195】 Going Home(KM算法求最小权匹配)
[POJ 2195] Going Home(KM算法求最小权匹配) Going Home Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- Human Gene Functions
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18053 Accepted: 1004 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
随机推荐
- 关于android studio3.0版本后引入资源问题error: failed linking file resources
最近更新阿里短视频的SDK,导入demo项目时,发现两个问题: 1.频繁报错AAPT2 error: file not found.以为直接Sync重新编译就可以,但是仍旧频繁提醒引入资源错误. 查找 ...
- PHP的Trait
PHP的Trait Trait是在PHP5.4中加入的,它既不是接口也不是类.主要是为了解决单继承语言的限制.是PHP多重继承的一种解决方案.例如,需要同时继承两个 Abstract Class, 这 ...
- 部署web应用到虚拟主机的三种方式
方式一: 在 [tomcat]/conf/server.xml 文件中的<Engine>标签下的<Host>标签内部, 添加一个 <Context ...
- [jquery] ajax parsererror
http://stackoverflow.com/questions/5061310/jquery-returning-parsererror-for-ajax-request 方法一: 直接去掉 d ...
- HDU 6315.Naive Operations-线段树(两棵树合并)(区间单点更新、区间最值、区间求和)+思维 (2018 Multi-University Training Contest 2 1007)
6315.Naive Operations 题意很好理解,但是因为区间求和求的是向下取整的a[i]/b[i],所以直接分数更新区间是不对的,所以反过来直接当a[i]==b[i]的时候,线段树对应的位置 ...
- (11)python 模块和包
一.导入模块和包 模块相当于一个.py文件,包相当于带有个__init__.py一个文件夹,既可按模块导入也可按包导入. 1.导入模块或包 import 包名或模块名 (as 别名),包名或模块名 ( ...
- JavaScript防止重复提交表单
往往有些用户网络慢或者其他问题,在提交表单的时候使劲点击保存提交按钮,在提交表单的时候加上下面的代码,即可以限制在一定时间内,只有一次点击是有效的. <script> var mypret ...
- AxureRP7超强部件库打包下载
摘要: 很多刚刚开始学习Axure的朋友都喜欢到网上搜罗各种部件库(组件库)widgets library ,但是网络中真正实用的并且适合你使用的少之又少,最好的办法就是自己制作适合自己工作内容的部件 ...
- ant脚本调用.bat文件
build.xml内容如下: <project name="example" default="test"> <target name=&qu ...
- Axis2 解析
代码生成 Java to WSDL:WSDL to Java:XSD to WSDL:WSDL to XML:WSDL to SOAP:WSDL to Service: Apache Axis2 ...