POJ 1080 Human Gene Functions
题意:给两个DNA序列,在这两个DNA序列中插入若干个'-',使两段序列长度相等,对应位置的两个符号的得分规则给出,求最高得分。
解法:dp。dp[i][j]表示第一个字符串s1的前i个字符和第二个字符串s2的前j个字符对齐时的最高得分,转移方程:dp[i][j] = max{dp[i - 1][j - 1] + a[s1[i]][s2[j]], dp[i - 1] + a[s1[i]]['-'] + dp[i][j - 1] + a['-'][s2[j]]},第一项表示对齐时s1[i]和s2[j]作为结尾,第二项表示对齐时'-'和s2[j]作为结尾,第三项表示对齐时s1[i]和'-'作为结尾。
注意dp应该以1开始,但字符串一般直接读入的话是以0开始的,因为这个样例一直过不去……调了好久……
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
int a[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 main()
{
int T;
while(~scanf("%d", &T))
{
while(T--)
{
string s1, s2;
int len1, len2;
cin >> len1 >> s1 >> len2 >> s2;
for(int i = 0; i < len1; i++)
if(s1[i] == 'A') s1[i] = 0;
else if(s1[i] == 'C') s1[i] = 1;
else if(s1[i] == 'G') s1[i] = 2;
else if(s1[i] == 'T')s1[i] = 3;
for(int i = 0; i < len2; i++)
if(s2[i] == 'A') s2[i] = 0;
else if(s2[i] == 'C') s2[i] = 1;
else if(s2[i] == 'G') s2[i] = 2;
else if(s2[i] == 'T') s2[i] = 3;
int dp[105][105] = {0};
for(int i = 1; i <= len1; i++)
dp[i][0] = dp[i - 1][0] + a[s1[i - 1]][4];
for(int i = 1; i <= len2; i++)
dp[0][i] = dp[0][i - 1] + a[4][s2[i - 1]];
for(int i = 1; i <= len1; i++)
for(int j = 1; j <= len2; j++)
dp[i][j] = max(dp[i - 1][j - 1] + a[s1[i - 1]][s2[j - 1]], max(dp[i - 1][j] + a[s1[i - 1]][4], dp[i][j - 1] + a[4][s2[j - 1]]));
printf("%d\n", dp[len1][len2]);
}
}
return 0;
}
POJ 1080 Human Gene Functions的更多相关文章
- 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 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
- poj 1080 Human Gene Functions(dp)
题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...
- dp poj 1080 Human Gene Functions
题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...
- POJ 1080 Human Gene Functions 【dp】
题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经 ...
- poj 1080 Human Gene Functions (最长公共子序列变形)
题意:有两个代表基因序列的字符串s1和s2,在两个基因序列中通过添加"-"来使得两个序列等长:其中每对基因匹配时会形成题中图片所示匹配值,求所能得到的总的最大匹配值. 题解:这题运 ...
- P 1080 Human Gene Functions
大概作了一周,终于A了 类似于求最长公共子序列,稍有变形 当前序列 ch1 中字符为 a,序列 ch2 中字符为 b 则有 3 种配对方式: 1. a 与 b 2. a 与 - 3. - 与 b 动态 ...
- HDU 1080 Human Gene Functions
最长公共子序列的变形 题目大意:给出两个基因序列,求这两个序列的最大相似度. 题目中的表格给出了两两脱氧核苷酸的相似度. 状态转移方程为: dp[i][j] = max(dp[i-1][j]+Simi ...
随机推荐
- 主题:PageRank解释
转自:http://www.iteye.com/topic/95079 PageRank解释 通过对由超过 50,000 万个变量和 20 亿个词汇组成的方程进行计算,PageRank 能够对网页的重 ...
- POJ 1862
#include <iostream> #include <algorithm> #include <iomanip> #include <cmath> ...
- C#图片上写文字
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Dr ...
- **使用 Git Hook 实现网站的自动部署
http://www.tuicool.com/articles/3QRB7jU 自动化能解放人类的双手,而且更重要的是,因为按照规定的流程来走,也减少了很多误操作的产生.不知道大家平时都是怎么样更新自 ...
- dynamic介绍
Visual C# 2010 引入了一个新类型 dynamic. 该类型是一种静态类型,但类型为 dynamic 的对象会跳过静态类型检查. 大多数情况下,该对象就像具有类型 object 一样. 在 ...
- Sina App Engine(SAE)入门教程(10)- Cron(定时任务)使用
参考资料 SAE Cron说明文档 Cron能干什么? cron 可以定时的触发一个脚本,在sae上最大的频率是一分钟一次.你可以用其来完成自己需要的业务逻辑,例如定期的抓取某些网页完菜信息的采集,定 ...
- Dropbox 有哪些鲜为人知的使用技巧?
作者:Feeng链接:http://www.zhihu.com/question/20104959/answer/13991578来源:知乎著作权归作者所有,转载请联系作者获得授权. 原文:The B ...
- ios 使用GCD 多线程 教程
什么是GCD Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法.该方法在Mac OS X 10.6雪豹中首次推出,并随后被引入到了iOS4.0中.GCD ...
- Android Apps开发环境搭建
一 Android开发工具简介 用于Eclipse的Android开发工具(AdnroidDeveloper Tools,简称ADT)插件提供了专业级别的开发环境,利用该环境来构建AndroidApp ...
- View的个得区域函数getHitRect,getDrawingRect,getLocalVisibleRect,getGlobalVisibleRect(*)
注意: OnCreate()函数中 调用下面函数,结果全为0,要等UI控件都加载完了才能得到绘制时的值. getHitRect 以父控件的左上为原点,计算当前view在父控件的区域,不管父控件在屏幕的 ...