poj 1080(sum初始化&数组下标i&最长公共自序列类型)
来源:互联网 发布:老师网络授课平台 编辑:程序博客网 时间:2024/06/14 07:45
Human Gene Functions
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 15979 Accepted: 8886
Description
It 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.
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
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input file. 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.
Output
The output should print the similarity of each test case, one per line.
Sample Input
2 7 AGTGATG 5 GTTAG 7 AGCTATT 9 AGCTTTAAA
Sample Output
1421
Source
Taejon 2001
有点类似最长公共自序列。
dp[i][j] = max(dp[i][j], dp[i-1][j] + mark[i]['-'], dp[i][j-1] + mark[j]['-'], dp[i-1][j-1] + mark[i][j]).
需要注意的是初始化的时候,dp[i][0] = sum(a[1] ~ a[i]) dp[0][j] = sum(b[1] ~ b[j]).
dp[0][0] = 0
提交记录:
1、Wrong Answer,因为sum在第二次计算dp[0][j] 的时候并没有初始化为0。
2、Wrong Answer,因为第二次计算dp[0][j] 的时候下标写错了。
3、Accepted!
- poj 1080(sum初始化&数组下标i&最长公共自序列类型)
- 3字符串求最长公共自序列
- 求解数组中最长递增自序列
- 最长上升自序列
- 最长递增自序列
- 最长递增自序列 python
- 最长上升自序列的另一种解法。
- hdu 4512 吉哥系列故事——完美队形I(最长公共上升自序加强版)
- hdu1069!求最长上升自序列的和
- UVA - 10599 Robots(II)(最长上升自序列)
- bzoj3173 最长上升自序列 块状链表
- 动态规划之最长上升自序列问题
- poj 1080 最长公共子串变形
- POJ 1080(最长公共子序列)
- 【后缀数组求最长公共子串】POJ 2774
- poj 2774 后缀数组 最长公共子串
- 后缀数组之最长公共子串 poj 2774
- poj 2774 最长公共子串 后缀数组
- poj 2533(裸的LIS,很少见的水题)
- javamial邮件发送
- poj 3176(简单杨辉三角n*(n+1)/2)
- Jquery优化效率 提升性能解决方案
- 用StringBuffer里的insert方法把数组中的数用,分开
- poj 1080(sum初始化&数组下标i&最长公共自序列类型)
- 我花了18年时间才能和你坐在一起喝咖啡
- leetcode Median of Two Sorted Arrays
- Android控件之TextView跑马灯效果
- [NYLG-OJ] 77开灯问题(白书例题)
- 一步步安装Ubuntu 13.10服务器版
- 给初中语文老师的书法字库软件
- MongoDB相关文章
- 机器学习II. Linear Regression with One Variable (Week 1) 单特征线性回归