POJ1080(LCS变形)
Human Gene Functions
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2799 Accepted Submission(s): 1587
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.
/*
ID: LinKArftc
PROG: 1080.cpp
LANG: C++
*/ #include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define randin srand((unsigned int)time(NULL))
#define input freopen("input.txt","r",stdin)
#define debug(s) cout << "s = " << s << endl;
#define outstars cout << "*************" << endl;
const double PI = acos(-1.0);
const double e = exp(1.0);
const int inf = 0x3f3f3f3f;
const int INF = 0x7fffffff;
typedef long long ll; const int maxn = ;
int score[][] = {
{, -, -, -, -},
{-, , -, -, -},
{-, -, , -, -},
{-, -, -, , -},
{-, -, -, -, }
}; char ch_str1[maxn], ch_str2[maxn];
int str1[maxn], str2[maxn];
int dp[maxn][maxn]; int main() {
int T;
int len1, len2;
scanf("%d", &T);
while (T --) {
scanf("%d %s", &len1, ch_str1);
scanf("%d %s", &len2, ch_str2);
for (int i = ; i < len1; i ++) {
if (ch_str1[i] == 'A') str1[i] = ;
else if (ch_str1[i] == 'C') str1[i] = ;
else if (ch_str1[i] == 'G') str1[i] = ;
else if (ch_str1[i] == 'T') str1[i] = ;
else str1[i] = ;
}
for (int i = ; i < len2; i ++) {
if (ch_str2[i] == 'A') str2[i] = ;
else if (ch_str2[i] == 'C') str2[i] = ;
else if (ch_str2[i] == 'G') str2[i] = ;
else if (ch_str2[i] == 'T') str2[i] = ;
else str2[i] = ;
}
memset(dp, , sizeof(dp));
for (int i = ; i <= len1; i ++) dp[i][] = dp[i-][] + score[str1[i-]][];
for (int i = ; i <= len2; i ++) dp[][i] = dp[][i-] + score[][str2[i-]];
for (int i = ; i <= len1; i ++) {
for (int j = ; j <= len2; j ++) {
dp[i][j] = max(dp[i-][j-] + score[str1[i-]][str2[j-]],
max(dp[i][j-] + score[][str2[j-]], dp[i-][j] + score[str1[i-]][]));
}
}
printf("%d\n", dp[len1][len2]);
} return ;
}
POJ1080(LCS变形)的更多相关文章
- 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 ...
- POJ 1080( LCS变形)
题目链接: http://poj.org/problem?id=1080 Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K ...
- UVA-1625-Color Length(DP LCS变形)
Color Length(UVA-1625)(DP LCS变形) 题目大意 输入两个长度分别为n,m(<5000)的颜色序列.要求按顺序合成同一个序列,即每次可以把一个序列开头的颜色放到新序列的 ...
- Advanced Fruits(HDU 1503 LCS变形)
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- poj1080--Human Gene Functions(dp:LCS变形)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17206 Accepted: ...
- HDU 5791 Two ——(LCS变形)
感觉就是最长公共子序列的一个变形(虽然我也没做过LCS啦= =). 转移方程见代码吧.这里有一个要说的地方,如果a[i] == a[j]的时候,为什么不需要像不等于的时候那样减去一个dp[i-1][j ...
- uva 10723 Cyborg Genes(LCS变形)
题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=107450#problem/C 题意:输入两个字符串,找一个最短的串,使得输入的两个 ...
- Combine String---hdu5727 &&& Zipper(LCS变形)
题目链接:http://poj.org/problem?id=2192 http://acm.split.hdu.edu.cn/showproblem.php?pid=5707 http://acm. ...
- HUST 4681 String (DP LCS变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4681 题目大意:给定三个字符串A,B,C 求最长的串D,要求(1)D是A的字序列 (2)D是B的子序列 ...
随机推荐
- QSS 的选择器
本文连接地址:http://www.qtdebug.com/QSS-Selector.html 选择器决定了 style sheet 作用于哪些 Widget,QSS 支持 CSS2 定义的所有选择器 ...
- Python 3基础教程25-异常处理
在Python中,异常处理,主要是try except语句,通常语法格式如下. try: 代码块1 except Exception as e: print(e) 代码2 接着前面读取CSV文件,如果 ...
- SQL 语句中 exists和not exists的用法
exists (sql 返回结果集,为真) not exists (sql 不返回结果集,为真) 如下: 表A ID NAME ...
- Hadoop伪分布式集群
一.HDFS伪分布式环境搭建 Hadoop分布式文件系统(HDFS)被设计成适合运行在通用硬件(commodity hardware)上的分布式文件系统.它和现有的分布式文件系统有很多共同点.但同时, ...
- 九度OJ--1165(C++)
#include <iostream>#include <string>#include <vector> using namespace std; int mai ...
- anaconda常用的命令
常用操作命令: 一.环境操作 1.查看环境管理的全部命令帮助: conda env -h 2.查看当前系统下的环境: conda info -e 3.创建环境: conda create env_na ...
- MongoDB复制二:复制集的管理
1.修改oplog的大小 需要在每个机器上都配置.先在secondary上操作,最后在primary上操作. 1)以单机的方式重启复制集的实例 db.shutdownServer() 在新的端口中启 ...
- HDU 4757 Tree(可持久化字典树)(2013 ACM/ICPC Asia Regional Nanjing Online)
Problem Description Zero and One are good friends who always have fun with each other. This time, ...
- JavaSE复习(五)网络编程
客户端:java.net.Socket 类表示.创建Socket对象,向服务端发出连接请求,服务端响应请求,两者建立连接开始通信 服务端:java.net.ServerSocket 类表示.创建Ser ...
- 【iOS开发】多线程下NSOperation、NSBlockOperation、NSInvocationOperation、NSOperationQueue的使用
http://blog.csdn.net/crycheng/article/details/21799611 本篇文章主要介绍下多线程下NSOperation.NSBlockOperation.NSI ...