【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 ...
随机推荐
- Bootstrap模态框垂直居中展示的方法
在bootstrap.js中加入以下代码:
- Delphi:对TNotifyEvent的理解
type TNotifyEvent = procedure (Sender: TObject) of object; 在Delphi中事件也是一个类,类型就是事件类型,不同的事件属于不同的类.TNot ...
- 打印sql语句方法
var_dump($this->blackpool_model->getLastSql());
- [BZOJ2553][BeiJing2011]禁忌 dp+AC自动机+矩阵快速幂
2553: [BeiJing2011]禁忌 Time Limit: 20 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 1206 Solved ...
- [BZOJ4537][Hnoi2016]最小公倍数 奇怪的分块+可撤销并查集
4537: [Hnoi2016]最小公倍数 Time Limit: 40 Sec Memory Limit: 512 MBSubmit: 1474 Solved: 521[Submit][Stat ...
- HDU 2586.How far away ?-离线LCA(Tarjan)
2586.How far away ? 这个题以前写过在线LCA(ST)的,HDU2586.How far away ?-在线LCA(ST) 现在贴一个离线Tarjan版的 代码: //A-HDU25 ...
- 湖南师范大学2018年大学生程序设计竞赛新生赛 A 齐神和心美的游戏【hash】
[链接]:A [题意]:给你n个数的序列和k.判断是否可以三个数组成k(同一个数可以拿多次) [分析]:每个数vis记录一下.2层循环.两数之和不超过k以及剩下的数出现在序列中那么ok. [代码]: ...
- CodeForces 669B
链接:http://codeforces.com/problemset/problem/669/B 本文链接:http://www.cnblogs.com/Ash-ly/p/5443086.html ...
- 11、Flask实战第11天:蓝图
蓝图的基本使用 之前我们写的代码都是集中在一个主程序文件里面.这样不利于分层解耦和维护.蓝图的作用就是让我们的flask项目更加模块化结构更加清晰,可以将相同模块的视图函数放在同一个蓝图下,同一个文件 ...
- 【动态规划】Gym - 100923A - Por Costel and Azerah
azerah.in / azerah.out Por Costel the Pig has received a royal invitation to the palace of the Egg-E ...