Human Gene Functions POJ 1080 最长公共子序列变形
Description
A human gene can be identified through a series of time-consuming biological experiments, often with the help of computer programs. Once a sequence of a gene is obtained, the next job is to determine its function. 
One of the methods for biologists to use in determining the function of a new gene sequence that they have just identified is to search a database with the new gene as a query. The database to be searched stores many gene sequences and their functions – many researchers have been submitting their genes and functions to the database and the database is freely accessible through the Internet.
A database search will return a list of gene sequences from the database that are similar to the query gene. 
Biologists assume that sequence similarity often implies functional similarity. So, the function of the new gene might be one of the functions that the genes from the list have. To exactly determine which one is the right one another series of biological experiments will be needed.
Your job is to make a program that compares two genes and determines their similarity as explained below. Your program may be used as a part of the database search if you can provide an efficient one. 
Given two genes AGTGATG and GTTAG, how similar are they? One of the methods to measure the similarity 
of two genes is called alignment. In an alignment, spaces are inserted, if necessary, in appropriate positions of 
the genes to make them equally long and score the resulting genes according to a scoring matrix.
For example, one space is inserted into AGTGATG to result in AGTGAT-G, and three spaces are inserted into GTTAG to result in –GT--TAG. A space is denoted by a minus sign (-). The two genes are now of equal 
length. These two strings are aligned:
AGTGAT-G 
-GT--TAG
In this alignment, there are four matches, namely, G in the second position, T in the third, T in the sixth, and G in the eighth. Each pair of aligned characters is assigned a score according to the following scoring matrix. 
denotes that a space-space match is not allowed. The score of the alignment above is (-3)+5+5+(-2)+(-3)+5+(-3)+5=9.
Of course, many other alignments are possible. One is shown below (a different number of spaces are inserted into different positions):
AGTGATG 
-GTTA-G
This alignment gives a score of (-3)+5+5+(-2)+5+(-1) +5=14. So, this one is better than the previous one. As a matter of fact, this one is optimal since no other alignment can have a higher score. So, it is said that the 
similarity of the two genes is 14.
Input
Output
Sample Input
2
7 AGTGATG
5 GTTAG
7 AGCTATT
9 AGCTTTAAA
Sample Output
14
21
Source
注意边界条件的处理!
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 109
#define MOD 1000000
#define INF 1000000009
#define eps 0.00000001
/*
最长子序列求出来
然后和原序列匹配
*/
char a[MAXN], b[MAXN];
int l1, l2, dp[MAXN][MAXN], g[MAXN][MAXN];
void Init()
{
g['A']['A'] = g['C']['C'] = g['T']['T'] = g['G']['G'] = ;
g['A']['C'] = g['C']['A'] = g['A']['T'] = g['T']['A'] = -;
g['A']['G'] = g['G']['A'] = -;
g['C']['T'] = g['T']['C'] = -;
g['G']['T'] = g['T']['G'] = -;
g['C']['G'] = g['G']['C'] = -;
g['A']['A' - ] = -;
g['C']['C' - ] = -;
g['G']['G' - ] = -;
g['T']['T' - ] = -;
}
int main()
{
Init();
int T; scanf("%d", &T);
while (T--)
{
memset(dp, - INF, sizeof(dp));
scanf("%d%s\n%d%s", &l1, a+, &l2, b+);
dp[][] = ;
for (int i = ; i <= l1; i++)
{
dp[i][] = dp[i - ][] + g[a[i]][a[i] - ];
}
for (int i = ; i <= l2; i++)
{
dp[][i] = dp[][i - ] + g[b[i]][b[i] - ];
}
for (int i = ; i <= l1; i++)
{
for (int j = ; j <= l2; j++)
{
if(a[i]==b[j])
dp[i][j] = dp[i - ][j - ] + g[a[i]][b[j]];
else
dp[i][j] = max(max(dp[i - ][j] + g[a[i]][a[i] - ], dp[i][j - ] + g[b[j]][b[j] - ]),dp[i-][j-]+g[a[i]][b[j]]);
}
}
//solve(l1, l2);
printf("%d\n", dp[l1][l2]);
}
}
Human Gene Functions POJ 1080 最长公共子序列变形的更多相关文章
- POJ 2250(最长公共子序列  变形)
		
Description In a few months the European Currency Union will become a reality. However, to join the ...
 - POJ 1458 最长公共子序列(dp)
		
POJ 1458 最长公共子序列 题目大意:给出两个字符串,求出这样的一 个最长的公共子序列的长度:子序列 中的每个字符都能在两个原串中找到, 而且每个字符的先后顺序和原串中的 先后顺序一致. Sam ...
 - poj 1080 Human Gene Functions (最长公共子序列变形)
		
题意:有两个代表基因序列的字符串s1和s2,在两个基因序列中通过添加"-"来使得两个序列等长:其中每对基因匹配时会形成题中图片所示匹配值,求所能得到的总的最大匹配值. 题解:这题运 ...
 - POJ 1458 最长公共子序列
		
子序列就是子序列中的元素是母序列的子集,且子序列中元素的相对顺序和母序列相同. 题目要求便是寻找两个字符串的最长公共子序列. dp[i][j]表示字符串s1左i个字符和s2左j个字符的公共子序列的最大 ...
 - POJ 1458 最长公共子序列 LCS
		
经典的最长公共子序列问题. 状态转移方程为 : if(x[i] == Y[j]) dp[i, j] = dp[i - 1, j - 1] +1 else dp[i, j] = max(dp[i - 1 ...
 - 【简单dp】poj 1458 最长公共子序列【O(n^2)】【模板】
		
最长公共子序列可以用在下面的问题时:给你一个字符串,请问最少还需要添加多少个字符就可以让它编程一个回文串? 解法:ans=strlen(原串)-LCS(原串,反串); Sample Input abc ...
 - hdu 1080 dp(最长公共子序列变形)
		
题意: 输入俩个字符串,怎样变换使其所有字符对和最大.(字符只有'A','C','G','T','-') 其中每对字符对应的值如下: 怎样配使和最大呢. 比如: A G T G A T G - G ...
 - POJ 1159 Palindrome-最长公共子序列问题+滚动数组(dp数组的重复利用)(结合奇偶性)
		
Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...
 - hdu1503 最长公共子序列变形
		
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1503 题意:给出两个字符串 要求输出包含两个字符串的所有字母的最短序列.注意输出的顺序不能 ...
 
随机推荐
- hibernate字段名和属性
			
字段名和属性名相同 Annotation:默认为@Basic 注意:如果在成员属性没有加入任何注解,则默认在前面加入了@Basic Xml中不用写column 字段名和属性名不同 Annotation ...
 - CSS伪类对象before和after的实例
			
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
 - Windows虚拟机中无法传输Arduino程序的问题
			
现象 最近儿子在学习机器人编程,其中有一步需要把板子和电脑用USB线相连接,然后把在电脑中编辑好的程序传输到Arduino板子上.在Windows笔记本上能正常工作,但在我的Mac笔记本的Window ...
 - 高德,百度,Google地图定位偏移以及坐标系转换
			
一.在进行地图开发过程中,我们一般能接触到以下三种类型的地图坐标系: 1.WGS-84原始坐标系 一般用国际GPS纪录仪记录下来的经纬度,通过GPS定位拿到的原始经纬度,Google和高德地图定位的的 ...
 - Django与 Ajax
			
什么是json? 定义: JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式.它基于 ECMAScript (w3c制定的js规范)的一个子 ...
 - SQL Sever语言 存储过程及触发器
			
存储过程:就像函数一样的会保存在数据库中-->可编程性-->存储过程 创建存储过程: 保存在数据库表,可编程性,存储过程create proc jiafa --需要的参数@a int,@b ...
 - Leetcode0006--ZigZag Conversion
			
[转载请注明]https://www.cnblogs.com/igoslly/p/9017638.html 来看一下题目: The string "PAYPALISHIRING" ...
 - 【PostgreSQL-9.6.3】分区表
			
PostgreSQL中的分区表是通过表继承来实现的(表继承博客http://www.cnblogs.com/NextAction/p/7366607.html).创建分区表的步骤如下: (1)创建“父 ...
 - js 攻坚克难
			
new new : 官方解释: 如果在一个函数前面带上new来调用,那么背地里将会创建一个连接到该函数的prototype的成员的新对象,同时this会被绑定到哪个新对象上: new 是用来创建对象的 ...
 - HDU_1068_Girls and Boys_二分图匹配
			
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...