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. lambda表达式和闭包

    lambda表达式和闭包 熟悉的Javascript或者Ruby的同学,可能对另一个名词:闭包更加熟悉.因为一般闭包的示例代码,长得跟lambda差不多,导致我也在以前很长一段时间对这两个概念傻傻分不 ...

  2. poj 2774 Long Long Message,后缀数组,求最长公共子串 hdu1403

    题意:给出两个字符串,求最长公共子串的长度. 题解:首先将两个字符串连在一起,并在中间加一个特殊字符(字串中不存在的)切割,然后两个串的最长公共字串就变成了全部后缀的最长公共前缀.这时就要用到heig ...

  3. 在windows下完美安装GitHub

    笔者最近在Windows下安装GitHub,过程中遇到不少问题.现在把安装的详细步骤分享给大家,免得大家走弯路. 笔者安装了GitHub for Windows程序,一切都运行顺利.但事情没有结束,首 ...

  4. sharepoint 自定义字段实现省市联动

    最后实现效果如下:设置栏如下:解决方案结构如下: fldtypes_RoyCustomField.xml 内容如下: <?xml version="1.0" encoding ...

  5. 在数组中找几个数的和等于某个数[LeetCode]

    首先明确一点,这个方面的问题设计到的知识点是数组的查找的问题.对于类似的这样的查找操作的具体办法就是三种解决方法: 1.暴力算法,多个for循环,很高的时间复杂度 2.先排序,然后左右夹逼,但是这样会 ...

  6. Dojo实现Tabs页报错(二)

  7. MVC-03 控制器(3)

    Controller负责处理浏览器来的所有要求,并决定响应什么属性给浏览器,以及协调Model与View之间的数据传递.在ASP.NET MVC中有好几种传递数据给视图的方式,例如从ASP.NET M ...

  8. 安装VMware vSphere 的目的就是在一台物理服务器上安装很多很多的虚拟机

    版权声明:本文为博主原创文章,未经博主允许不得转载. 我们安装VMware vSphere 的目的就是在一台物理服务器上安装很多很多的虚拟机,我们可以通过VMware vSphere Client直接 ...

  9. 磁珠在PCB中的应用

    1.磁珠的单位是欧姆,而不是亨特,这一点要特别注意.因为磁珠的单位是按照它在某一频率产生的阻抗来标称的,阻抗的单位也是欧姆.磁珠的 DATASHEET上一般会提供频率和阻抗的特性曲线图,一般以100M ...

  10. PC游戏编程(入门篇)(前言写的很不错)

    PC游戏编程(入门篇) 第一章 基石 1. 1 BOSS登场--GAF简介 第二章 2D图形程式初体验 2.l 饮水思源--第一个"游戏"程式 2.2 知其所以然一一2D图形学基础 ...