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 ...
随机推荐
- matlab特殊符号表
Character Sequence Symbol Character Sequence Symbol Character Sequence Symbol \alpha α \upsilon υ \s ...
- bzoj 1179 [Apio2009]Atm 缩点+最短路
[Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 4290 Solved: 1893[Submit][Status][Dis ...
- 浅谈移动端三大viewport
我们通常在写移动端页面时,往往都会在html页面中加入这样一段话 <meta name="viewport" content="width=device-width ...
- 什么叫TLD、gTLD、nTLD、ccTLD、iTLD 以及几者之间的关系
TLD TLD的全称是Top Level Domain,顶级域名,它是一个因特网域名的最后部分,也就是任何域名的最后一个点后面的字母组成的部分. 最早的顶级域名有:.com(公司和企业)..net(网 ...
- 图论:最短路-Bellman-Ford
我们之前介绍了一种,(最常用的)SPFA算法,SPFA算法是对Bellman-Ford算法的队列优化,用队列替代了Bellman-Ford中的循环检查部分 然后这里我们介绍Bellman-Ford算法 ...
- c# “XXX::Invoke”类型的已垃圾回收委托进行了回调。这可能会导致应用程序崩溃、损坏和数据丢失。向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们。
症状描述如下: 如果将一个委托作为函数指针从托管代码封送到非托管代码,并且在对该委托进行垃圾回收后对该函数指针发出了一个回调,则将激活 callbackOnCollectedDelegate 托管调试 ...
- jsp05 指令与动作
JSP7个动作指令如下 : jsp:forward: 执行页面转向,将请求的处理转发到下一个页面. jsp:param: 用于传递参数,必须与其他支持参数曲标签一起使用. jsp:include: 用 ...
- 完美解决小米pro风扇乱转的问题
新买的小米Pro顶配,发现CPU高于20%的时候就开始狂响,最后找到了解决的方法,但是不知道会有什么影响.方法如下: 在平衡模式下更改高级电源设置--->处理器电源管理--->最大出来状态 ...
- Linux 文件编码问题及iconv命令
iconv命令是运行于linux/unix平台的文件编码装换工具.当我们在linux/unix系统shell查看文本文件时,常常会发现文件的中文是乱码的,这是由于文本文件的编码与当前操作系统设置的编码 ...
- Ribbon/Feign/Zuul retry
原文 https://github.com/spring-cloud/spring-cloud-netflix/issues/1577 I'm using Spring Cloud Camden SR ...