http://poj.org/problem?id=1080

知识点 :最长公共子序列

要点:

转移方程  f[i][j]  = max{ f[i-i][j]+score[s1[i-1]]['-'],  f[i][j-1]+score['-'][s2[j-1]],  f[i-1][j-1]+score[s1[i-1]][s2[j-1]]}

#include <iostream>

using namespace std;
int score['T'+]['T'+];
int dp[][];
char s1[],s2[];
void init(){
score['A']['A']=;
score['C']['C'] =;
score['G']['G'] =;
score['T']['T'] =;
score['-']['-'] = -;
score['A']['C'] = score['C']['A']=-;
score['A']['G'] = score['G']['A']=-;
score['A']['T'] = score['T']['A']=-;
score['A']['-'] = score['-']['A']=-;
score['C']['G'] = score['G']['C']=-;
score['C']['T'] = score['T']['C']=-;
score['C']['-'] = score['-']['C']=-;
score['G']['T'] = score['T']['G']=-;
score['G']['-'] = score['-']['G']=-;
score['T']['-'] = score['-']['T']=-;
} int mx(int a,int b,int c){
int k = a>b?a:b;
return c>k?c:k;
}
int main()
{
init();
int t;
cin>>t;
while(t--){
int len1,len2;
cin>>len1>>s1>>len2>>s2;
dp[][] =;
for(int i=;i<=len1;i++){
dp[i][] = dp[i-][]+score[s1[i-]]['-'];
}
for(int j=;j<=len2;j++){
dp[][j] = dp[][j-]+score['-'][s2[j-]];
}
for(int i=;i<=len1;i++){
for(int j=;j<=len2;j++){
int temp1 = dp[i-][j]+score[s1[i-]]['-'];
int temp2 = dp[i][j-]+score['-'][s2[j-]];
int temp3 = dp[i-][j-]+score[s1[i-]][s2[j-]];
dp[i][j] = mx(temp1,temp2,temp3);
}
}
cout<<dp[len1][len2]<<endl;
}
return ;
}

poj 1080的更多相关文章

  1. poj 1080 zoj 1027(最长公共子序列变种)

    http://poj.org/problem?id=1080 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=27 /* zoj ...

  2. 【POJ 1080】 Human Gene Functions

    [POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...

  3. poj 1080 Human Gene Functions(dp)

    题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...

  4. POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)

    题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...

  5. poj 1080 dp如同LCS问题

    题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...

  6. dp poj 1080 Human Gene Functions

    题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...

  7. POJ 1080( LCS变形)

    题目链接: http://poj.org/problem?id=1080 Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K ...

  8. POJ - 1080 枚举 / DP

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

  9. 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 ...

随机推荐

  1. 源码安装rsyslog

    <pre name="code" class="html">下载下列软件 json-c-0.12-20140410.tar.gz---------- ...

  2. 【基础】常用的机器学习&数据挖掘知识点

    Basis(基础): MSE(Mean Square Error 均方误差),LMS(LeastMean Square 最小均方),LSM(Least Square Methods 最小二乘法),ML ...

  3. Uber到底挣钱不挣钱,听听司机怎么说

    “根本不挣钱.”Joel开着他崭新的丰田凯美瑞混合动力车,在硅谷早晨的濛濛细雨中,不无幽怨地说.Joel是一名Uber司机,从坐上他车的那一刻起,他的抱怨便一直没停过:“过去日子还挺好过,一个月靠开U ...

  4. iOS 检测更新版本

    获取app版本URL 数字是appID,在开发者账号app信息中可以找到 #define APP_URL @"http://itunes.apple.com/cn/lookup?id=116 ...

  5. Ext2文件系统布局,文件数据块寻址,VFS虚拟文件系统

    注:本分类下文章大多整理自<深入分析linux内核源代码>一书,另有参考其他一些资料如<linux内核完全剖析>.<linux c 编程一站式学习>等,只是为了更好 ...

  6. slots

    class Student(object): pass s = Student() s.name = 'Michael' print(s.name) def set_age(self, age): s ...

  7. eclipse SVN 安装

    1.下载最新的Eclipse,我的版本是3.7.2 indigo(Eclipse IDE for Java EE Developers)版    如果没有安装的请到这里下载安装:http://ecli ...

  8. X509Certificate2 本地正常,放到线上内部错误

    iis 找到部署的站点应用连接池,右键高级设置,找到“加载用户配置文件”改为true.window service2008 默认为false的.

  9. Android 开发笔记“context和getApplicationContext”

    在android中常常会遇到与context有关的内容 浅论一下context : 在语句 AlertDialog.Builder builder = new AlertDialog.Builder( ...

  10. 0603 python 基础02

    作业1:ANSI和utf8的区别? ASCII是用来表示英文字符的一种编码规范,每个ASCII字符占用1个字节(8bits). 可以表示的最大字符数是256,一般只用前128个(最高位为0),其中包括 ...