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. HDU 5828 Rikka with Sequence(线段树)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5828 [题目大意] 给出一个数列,要求支持区间加法,区间开方和区间和查询操作. [题解] 考虑开方 ...

  2. HDU 1012 u Calculate e

    题解:直接模拟 #include <cstdio> int main(){ puts("n e");puts("- -----------");pu ...

  3. Candy----HDU4465----数学题

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4465 题目意思: 有两个箱子,每个箱子装有N个糖果 打开第一个箱子的概率是P,另外一个就是1-P 当小 ...

  4. Cocos2d-x:环境配置小节

    一.准备 须要下载下面内容. 1. vs2010 下载地址:http://download.microsoft.com/download/1/4/3/143B7583-6225-474F-88D5-5 ...

  5. BZOJ 3223: Tyvj 1729 文艺平衡树(splay)

    速度居然进前十了...第八... splay, 区间翻转,用一个类似线段树的lazy标记表示是否翻转 ------------------------------------------------- ...

  6. iOS自动自动隐藏软键盘

    自动隐藏软键盘,分为两步,一个是单击软键盘外部任意空间:另外一个是单击软键盘上的return键.下面依次实现 单击软键盘外部空间键隐藏软键盘: 一:在viewDidLoad中添加一个UITabGest ...

  7. git版本控制的笔记

    一.配置你的身份,提交代码时git就可以知道是谁提交的了 git config --global user.name "Tony" git config --global user ...

  8. Linux中fork()函数详解(转)

    一.fork入门知识 一个进程,包括代码.数据和分配给进程的资源.fork()函数通过系统调用创建一个与原来进程几乎完全相同的进程,也就是两个进程可以做完全相同的事,但如果初始参数或者传入的变量不同, ...

  9. Xamarin几十篇博客,roslyn和dotnet也开源了

    .Net 基金会 http://www.dotnetfoundation.org/ 更新的真快,刚打完2的补丁包,3就粗来了............ https://www.visualstudio. ...

  10. 宣布在日本地区正式发布 Windows Azure

     昨天,我与 Microsoft 日本的集团副总裁 Yasuyuki Higuchi 一同站在台上,宣布在两个新地区正式发布 Windows Azure:日本东部和日本西部.能够亲自见证 Micr ...