HDU 1080 Human Gene Functions--DP--(变形最长公共子)

意甲冠军:该基因序列的两端相匹配,四种不同的核苷酸TCGA有不同的分值匹配。例如T—G比分是-2,它也可以被加入到空格,空洞格并且还具有一个相应的核苷酸匹配分值,求最大比分

分析:

在空气中的困难格的数量和位置不确定

二维dp,dp[i][j]表示序列a的前i段和序列b的前j段匹配时的最大分数。

接下来细致分析当i和j匹配的情况:1.a[i]与b[j]匹配;2.a[i]与b[j-1]。3.a[i]与b[j+1]。

所以方程:dp [i][j]=  max(dp[i-1][j]+mat[i][‘#‘],dp[i][j-1]+mat[‘#‘][j],dp[i-1][j-1]+mat[i][j])

代码:

#include<iostream>
#include<string>
#include<cstring>
#define INF 0x3f3f3f3f
using namespace std;
int t,n,m,dp[200][200];
string a,b;
int mat[200][200];
int max(int a,int b)
{
	return a>b?

a:b;
}
void f()
{
	mat['A']['A']=5;	mat['C']['C']=5;	mat['G']['G']=5;
	mat['T']['T']=5;	mat['A']['C']=-1;	mat['A']['G']=-2;
	mat['A']['T']=-1;	mat['A']['#']=-3;	mat['C']['A']=-1;
	mat['C']['G']=-3;	mat['C']['T']=-2;	mat['C']['#']=-4;
	mat['G']['A']=-2;	mat['G']['C']=-3;	mat['G']['T']=-2;
	mat['G']['#']=-2;	mat['T']['A']=-1;	mat['T']['C']=-2;
	mat['T']['G']=-2;	mat['T']['#']=-1;	mat['#']['A']=-3;
	mat['#']['C']=-4;	mat['#']['G']=-2;	mat['#']['T']=-1;
	mat['#']['#']=-INF;

}
int main()
{
    f();
	cin>>t;
	while(t--){
		cin>>n>>a;
		cin>>m>>b;
		dp[0][0]=0;
		for(int i=1;i<=n;i++) dp[i][0]=dp[i-1][0]+mat[a[i-1]]['#'];
		for(int i=1;i<=m;i++) dp[0][i]=dp[0][i-1]+mat['#'][b[i-1]];
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				dp[i][j]=max(dp[i-1][j-1]+mat[a[i-1]][b[j-1]],
				max(dp[i-1][j]+mat[a[i-1]]['#'],dp[i][j-1]+mat['#'][b[j-1]]));
			}
		}
		cout<<dp[n][m]<<endl;
	}
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

时间: 2024-10-27 02:08:06

HDU 1080 Human Gene Functions--DP--(变形最长公共子)的相关文章

HDU 1080 Human Gene Functions

最长公共子序列的变形 题目大意:给出两个基因序列,求这两个序列的最大相似度. 题目中的表格给出了两两脱氧核苷酸的相似度. 状态转移方程为: dp[i][j] = max(dp[i-1][j]+Similarity(s1[i], '-'),                     dp[i][j-1]+Similarity(s2[j], '-'),                     dp[i-1][j-1]+Similarity(s1[i], s2[j])); 注意边界的初始化. 1 //#

POJ 1080 Human Gene Functions(DP)

Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18007   Accepted: 10012 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

hdu 1080 Human Gene Functions (动态规划)

Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2402    Accepted Submission(s): 1360 Problem Description It is well known that a human gene can be considered as a sequence,

hdu 1080 Human Gene Functions(DP)

题意: 人类基因由A.C.G.T组成. 有一张5*5的基因表.每格有一个值,叫相似度.例:A-C:-3.意思是如果A和C配对, 则它俩的相似度是-3[P.S.:-和-没有相似度,即-和-不能配对] 现在给两条基因片段.(长度不一定相等) 现在你要在两条基因片段中插入若干个-(空白基因),使得两个基因片段长度相等,且得到的整体相似度的值最大.[再次P.S.:-和-不能配对] 思路: 因为-和-不能匹配,所以插入的-的个数是有限的. str1的第一个基因可以与str1的第一个或-配对.然后,,,,很

POJ 1080 Human Gene Functions(求两字符串相似度:LCS变形)

POJ 1080 Human Gene Functions(求两字符串相似度:LCS变形) http://poj.org/problem?id=1080 题意: HDU1080 给你两个由字符A,C,G,T构造的字符串s1和s2, 现在你可以在这两个字符串中插入空格, 使得两串长相等(但是不能使得s1的空格对应s2的空格位置). 然后给你s1的特定字符对应s2中特定字符所能获得的分数矩阵: 问你最后两个字符串所能获得的最大分数是多少? 分析: 本题很类似于求字符串最短编辑距离或者求字符串LCS的

P 1080 Human Gene Functions

大概作了一周,终于A了 类似于求最长公共子序列,稍有变形 当前序列 ch1 中字符为 a,序列 ch2 中字符为 b 则有 3 种配对方式: 1. a 与 b 2. a 与 - 3. - 与 b 动态转移方程: dp[i][j] = max(dp[i - 1][j - 1] + g(ch1[i],ch2[j]) , dp[i - 1][j] + g(ch1[i],'-') , dp[i][j-1] + g('-',ch2[j])) 代码如下: #include<stdio.h> #includ

POJ 1080 Human Gene Functions(动态规划)

一开始用的DFS,无限TLE,贴丑代码 //version 1 TLE #include<cstdio> #include<cstring> #include<iostream> #define MAX_INT 2147483647 #define MAXN 105 using namespace std; int Map[5][5] = { {0,-3,-4,-2,-1}, {-3,5,-1,-2,-1}, {-4,-1,5,-3,-2}, {-2,-2,-3,5,-

POJ 1080 Human Gene Functions(LCS)

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

POJ #1080 - Human Gene Functions

A classic 2D DP problem. A disguise of LCS - actually not very hard to decode: it is about 2 sequences' matching, though with a weight value of each match. The point of this problem: how to decode problem statement and how to distill the actuall mode

POJ - 1080 - Human Gene Functions (LCS的变形)

题目传送:Human Gene Functions 思路:LCS的变形,定义状态dp[ i ][ j ]为取字符串s前i个字符字符串t前j个字符所获得的最大值,则可以得到状态转移方程为: dp[ i ][ j ] = max(dp[ i ][ j - 1] + f[ ' - ' ][ t[ j ] ], dp[ i - 1 ][ j ] + f[ s [ i ] ][ ' - ' ], dp[i - 1][ j - 1] + f[ s [ i ] ][ t [ j ] ]); AC代码: #in