poj 1080

不要打我 ,存代码

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

#define maxx 105
int len1, len2, dp[maxx][maxx], s[200][200];
char g1[maxx], g2[maxx];
void init()
{
     s['A']['A'] = s['C']['C'] = s['G']['G'] = s['T']['T'] = 5;
     s['A']['C'] = s['C']['A'] = s['A']['T'] = s['T']['A'] = -1;
     s['A']['G'] = s['G']['A'] = s['C']['T'] = s['T']['C'] = -2;
     s['G']['T'] = s['T']['G'] = s['G']['-'] = s['-']['G'] = -2;
     s['A']['-'] = s['-']['A'] = s['C']['G'] = s['G']['C'] = -3;
     s['T']['-'] = s['-']['T'] = -1;
     s['C']['-'] = s['-']['C'] = -4;
}
int main()
{
    int n;
    init();
    scanf ("%d", &n);
    while (n--) {
    	memset(dp,0,sizeof(dp));
    scanf ("%d%s%d%s", &len1, g1+1, &len2, g2+1);
      int i, j;
    dp[0][0] = 0;
    for (i = 1; i <= len2; i++)
        dp[0][i] = dp[0][i-1] + s['-'][g2[i]];
    for (i = 1; i <= len1; i++)
        dp[i][0] = dp[i-1][0] + s[g1[i]]['-'];
    for (i = 1; i <= len1; i++) {
         for (j = 1; j <= len2; j++)
            dp[i][j] = max (dp[i-1][j-1] + s[g1[i]][g2[j]], max(dp[i][j-1] + s['-'][g2[j]], dp[i-1][j] + s[g1[i]]['-']));
    }
    printf("%d\n",dp[len1][len2]);
    }
    return 0;
}
时间: 2024-10-10 13:28:54

poj 1080的相关文章

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(动态规划)

一开始用的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变形)

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

【POJ 1080】 Human Gene Functions

[POJ 1080] Human Gene Functions 类似于最长公共子序列的做法 dp[i][j]表示 str1[i]对应str2[j]时的最大得分 转移方程为 dp[i][j]=max(dp[i-1][j-1]+score[str1[i]][str2[j]], max(dp[i-1][j]+score[str1[i]]['-'],dp[i][j-1]+score['-'][str2[j]]) ) 注意初始化0下标就好 代码如下: #include <iostream> #inclu

poj 1080 Human Gene Functions (dp,LCS)

链接:poj 1080 题意:给定两个字符串,求它们对齐匹配的最大值 要求:可以两个字符匹配,也可以一个字符和'-'匹配, 但是不能两个'-'匹配,例如: AGTGATG GTTAG 这两个字符串可以看成是 AGTGATG -GTTA-G 也可以看成是 AGTGAT-G -GT--TAG 分析:这是一个变形的最长公共子序列,最优解: 1.取字符i-1和j-1的时候dp[i][j]=dp[i-1][j-1]+a[s1[i-1]][s2[j-1]]; 2.取字符i-1,不取j-1的时候dp[i][j

POJ - 1080 枚举

要求max{F/P},先枚举下界lowf,再贪心求符合约束条件的n个最小价值和 记录F的离散值和去重可以大幅度常数优化 (本来想着用DP做的) (辣鸡POJ连auto都Complie Error) #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<vector> #include<iterator> using name

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][j] = max(dp[i][j-1],dp[i-1][j]); 边界:dp[0][j] = 0(j<b.size) ,dp[i][0] = 0(i< a.size); LCS变形: 设dp[i][j]为前i,j的最大价值: value(x, y)为比较价值: dp[i][j] = max(d

poj 1080 dp

基因配对 给出俩基因链和配对的值  求配对值得最大值  简单dp #include<iostream> #include<stdio.h> #include<string.h> using namespace std; const int maxa = 205; const int mina = -100000000; char str1[maxa], str2[maxa]; int num[5][5] = { 5, -1, -2, -1, -3, -1, 5, -3,