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. Netty那点事: 概述, Netty中的buffer, Channel与Pipeline

    Netty那点事(一)概述 Netty和Mina是Java世界非常知名的通讯框架.它们都出自同一个作者,Mina诞生略早,属于Apache基金会,而Netty开始在Jboss名下,后来出来自立门户ne ...

  2. java面向对象编程(类、对象)

    一.面向对象编程概述面向对象编程(Object  Oriented  Programming,缩写为OOP)是当今最流行的程序设计技术,它具有代码易于维护.可扩展性好和代码可常用等优点.面向对象的设计 ...

  3. Ubuntu下远程访问MySQL数据库

    MySQL远程访问的命令 格式: mysql -h主机地址 -u用户名 -p用户密码 jack@jack:~$ mysql -h192.168.5.154 -usaledata -pEnter pas ...

  4. 让微信二维码扫描你的APK

    二维码深入人心,很多App都在官网挂出了可以扫描下载apk的二维码,笔者所在公司的产品也不例外.一般二维码编码的URL不会直接放apk而是放中间地址,通过这个中间地址再跳转到apk所在URL,原因大概 ...

  5. 生产环境提升rman备份速度----启动块跟踪

    生产环境提升rman备份速度----启动块跟踪 [环境] AIX(5300-08).oracle10g(10.2.0.1.0-64bit) [目标] 因为生产环境数据量较大,欲加快rman备份的速度 ...

  6. 通过配置Tomcat,让Android真机通过局域网访问PC的文件

    在 Tomcat 根目录,找到conf\server.xml文件. 1.打开server.xml查找修改端口为8080端口: <Connector port="8080" p ...

  7. HDU3496-Watch The Movie

    描述: New semester is coming, and DuoDuo has to go to school tomorrow. She decides to have fun tonight ...

  8. A Byte of Python 笔记(5)函数:定义、形参、局部变量、默认参数、关键参数

    第7章  函数 函数是重要的程序段.它们允许你给一块语句一个名称,然后你可以在程序的任何地方使用这个名称任意多次地运行这个语句块.这被称为 调用 函数. 定义函数 函数通过 def 关键字定义.def ...

  9. Python学习之字符串函数

    下面是在看python核心编程中序列字符串中提到的一些函数,根据自己的学习理解总结了下,方便日后用到的时候查看.    1.string.capitalize() 把字符串的第一个字符大写 例子:   ...

  10. android screenOrientation

    Activity: android:screenOrientation 横(landscape)竖(portrait)屏显示. 如果想让它一直是横屏显示的话,xml:android:screenOri ...