hdu 1080(LCS变形)
Human Gene Functions
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3008 Accepted Submission(s): 1701
is well known that a human gene can be considered as a sequence,
consisting of four nucleotides, which are simply denoted by four
letters, A, C, G, and T. Biologists have been interested in identifying
human genes and determining their functions, because these can be used
to diagnose human diseases and to design new drugs for them.
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 consists of T test cases. The number of test cases ) (T is given
in the first line of the input. Each test case consists of two lines:
each line contains an integer, the length of a gene, followed by a gene
sequence. The length of each gene sequence is at least one and does not
exceed 100.
7 AGTGATG
5 GTTAG
7 AGCTATT
9 AGCTTTAAA
21
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#define N 105
using namespace std; int mp[][]=
{
{,-,-,-,-},
{-,,-,-,-},
{-,-,,-,-},
{-,-,-,,-},
{-,-,-,-,}
};
int dp[N][N];
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
int n,m;
char str1[],str2[];
scanf("%d%s",&n,str1+);
scanf("%d%s",&m,str2+);
memset(dp,,sizeof(dp));
int x,y;
for(int i=; i<=n; i++) ///这里很重要
{
if(str1[i]=='A') y=;
if(str1[i]=='C') y=;
if(str1[i]=='G') y=;
if(str1[i]=='T') y=;
dp[i][] = dp[i-][] + mp[y][];
}
for(int i=; i<=m; i++)
{
if(str2[i]=='A') x=;
if(str2[i]=='C') x=;
if(str2[i]=='G') x=;
if(str2[i]=='T') x=;
dp[][i] = dp[][i-] + mp[][x];
} for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{ if(str1[i]=='A') x=;
if(str1[i]=='C') x=;
if(str1[i]=='G') x=;
if(str1[i]=='T') x=;
if(str2[j]=='A') y=;
if(str2[j]=='C') y=;
if(str2[j]=='G') y=;
if(str2[j]=='T') y=;
dp[i][j] = max(dp[i-][j-]+mp[x][y],max(dp[i-][j]+mp[][x],dp[i][j-]+mp[][y]));
}
}
//for(int i=1;i<=n;i++)
printf("%d\n",dp[n][m]);
}
return ;
}
hdu 1080(LCS变形)的更多相关文章
- Advanced Fruits(HDU 1503 LCS变形)
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1243(LCS变形)
反恐训练营 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- POJ 1080( LCS变形)
题目链接: http://poj.org/problem?id=1080 Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K ...
- poj 1080 (LCS变形)
Human Gene Functions 题意: LCS: 设dp[i][j]为前i,j的最长公共序列长度: dp[i][j] = dp[i-1][j-1]+1;(a[i] == b[j]) dp[i ...
- hdu 1087(LIS变形)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- DP问题(3) : hdu 1080
题目转自hdu 1080,题目传送门 题目大意: 不想翻译! 解题思路: 其实就是一道变异的求lcs(Longest common subsequence 最长公共子序列)的题 不过,它的依据是下面这 ...
- UVA-1625-Color Length(DP LCS变形)
Color Length(UVA-1625)(DP LCS变形) 题目大意 输入两个长度分别为n,m(<5000)的颜色序列.要求按顺序合成同一个序列,即每次可以把一个序列开头的颜色放到新序列的 ...
- HDU 5791 Two ——(LCS变形)
感觉就是最长公共子序列的一个变形(虽然我也没做过LCS啦= =). 转移方程见代码吧.这里有一个要说的地方,如果a[i] == a[j]的时候,为什么不需要像不等于的时候那样减去一个dp[i-1][j ...
- hdu 1080 dp(最长公共子序列变形)
题意: 输入俩个字符串,怎样变换使其所有字符对和最大.(字符只有'A','C','G','T','-') 其中每对字符对应的值如下: 怎样配使和最大呢. 比如: A G T G A T G - G ...
随机推荐
- bzoj 1123 [POI2008]BLO Tarjan求割点
[POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1540 Solved: 711[Submit][Status][Discu ...
- HDU3336 KMP+DP
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 一个JAVA题引发的思考
转载自:http://www.cnblogs.com/heshan664754022/archive/2013/03/24/2979495.html 十年半山 今天在论坛闲逛的时候发现了一个很有趣的题 ...
- 确保web安全的https、确认访问用户身份的认证(第七章、第八章)
第七章 确保web安全的https 1.http的缺点: (1)通信使用明文,内容可能会被窃听 (2)不验证通信方的身份,因此有可能遭遇伪装 (3)无法证明报文的完整性,因此有可能已遭篡改. 2.通信 ...
- SpringBoot jar包不支持jsp
官方原文如下: When running a Spring Boot application that uses an embedded servlet container (and is packa ...
- c# socket select 模型代码(u3d)
其实写过多次网络链接.但是因为换了工作,又没电脑在身边,所以以前的代码都没办法翻出来用. 所以从今天起,一些常用的代码只好放到网上. 公司有一个局域网的游戏.本来想用u3d的rpc就可以完成.但是后来 ...
- 【POJ】1830 开关问题(高斯消元)
http://poj.org/problem?id=1830 高斯消元无解的条件:当存在非法的左式=0而右式不等于0的情况,即为非法.这个可以在消元后,对没有使用过的方程验证是否右式不等于0(此时因为 ...
- hibernate单列的多值查询
比如你的表主键是id,你要删除id 是 34,56,99 这样的.. uid是拼好的 比如 '34','56','99' ,以前我会这样写 String queryString = "upd ...
- 简易微信小程序签到功能
一.效果图 点击签到后 二.数据库 用一张数据表存用户签到的信息,每次用户签到都会往表中添加一条记录了用户id和签到日期的数据,如下图 三.后端 后端写两个接口,一个用于查询用户今日是否签到和签到记录 ...
- 如何用js自己实现Animate运动函数
js运动是我们学习js必不可少的研究部分,首先我们要知道js的运动其实仅仅是不断改变元素的某个属性值而已,比如不断改变一个绝对定位div的left值,那么你看到的效果就是这个div不断的向右边运动,那 ...