题目链接:http://poj.org/problem?id=1080

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std; const int maxn = ;
const int INF = 0x3f3f3f; int dp[maxn][maxn];
int A[maxn],B[maxn]; int mymap[][] = {
{, , , , , },
{,,-,-,-,- },
{,-,,-,-,- },
{,-,-,,-,- },
{,-,-,-,,- },
{,-,-,-,-, }
}; int tran(char ch){
int ret;
switch(ch){
case 'A' : ret = ; break;
case 'C' : ret = ; break;
case 'G' : ret = ; break;
case 'T' : ret = ; break;
}
return ret;
}
int main()
{
// freopen("E:\\acm\\input.txt","r",stdin);
int T;
cin>>T;
while(T--){
int lenA,lenB;
char a[maxn];
scanf("%d %s",&lenA,a+);
for(int i=;i<=lenA;i++) A[i] = tran(a[i]); scanf("%d %s",&lenB,a+);
for(int i=;i<=lenB;i++) B[i] = tran(a[i]); dp[][] = ;
for(int i=;i<=lenB;i++)
dp[][i] = dp[][i-] + mymap[][B[i]];
for(int i=;i<=lenA;i++)
dp[i][] = dp[i-][] + mymap[A[i]][]; // 初始化出现了问题,WA了一次。
for(int i=;i<=lenA;i++)
for(int j=;j<=lenB;j++){
if(A[i] == B[j])
dp[i][j] = dp[i-][j-] + mymap[A[i]][B[j]];
else{
int Max = max(dp[i-][j]+mymap[A[i]][],dp[i][j-]+mymap[][B[j]]);
dp[i][j] = max(dp[i-][j-] + mymap[A[i]][B[j]],Max);
}
}
printf("%d\n",dp[lenA][lenB]);
}
}

poj 1080 dp如同LCS问题的更多相关文章

  1. poj 1080 基因组(LCS)

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19376   Accepted:  ...

  2. poj 1080 dp

    基因配对 给出俩基因链和配对的值  求配对值得最大值  简单dp #include<iostream> #include<stdio.h> #include<string ...

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

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

  4. 【POJ 1080】 Human Gene Functions

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

  5. Poj 1936,3302 Subsequence(LCS)

    一.Description(3302) Given a string s of length n, a subsequence of it, is defined as another string ...

  6. POJ 1080:Human Gene Functions LCS经典DP

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18007   Accepted:  ...

  7. POJ 1080( LCS变形)

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

  8. hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)

    题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...

  9. dp poj 1080 Human Gene Functions

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

随机推荐

  1. Access restriction:The type JPEGCodec is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\rt.jar

    解决方法: Project -> Properties -> libraries, 先remove掉JRE System Library,然后再Add Library重新加入. ===== ...

  2. Android增加监听的三种实现方式

    在Android中,为一个按钮增加监听的方式有五种 1.匿名内部类 @Override protected void onCreate(Bundle savedInstanceState) { sup ...

  3. 禁用UITextField复制粘贴等方法

    要实现此功能只需创建一个继承自UITextField的子类,重写以下方法即可. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender{ ...

  4. win7下装ubuntu

    需要的东西有: 1,ubuntu系统镜像,下载地址:http://www.ubuntu.com/download/desktop 选64位吧,兼容性好些. 2,空闲的大于20G硬盘空间,这个大小根据个 ...

  5. 转载 VC 2010下安装OpenCV2.4.4

    说明: 1.安装平台:32位XP,VS2010: 2.OpenCV 2.4.4不支持VC 6.0: 3.网上有很多用CMake编译OpenCV的安装教程,这里建议先不要自己编译,如果使用预编译好的库有 ...

  6. Binary Tree Level Order Traversal 解题思路 ×

    要求: 树的层级遍历 思路: 1.两个队列,q1 q2 ,root放到q1 2.q1首元素出列,判断是否有左右孩子,有的话,放入q2.(循环此步骤值得q1为空) 3.q1 = q2,重复2,直到q1为 ...

  7. jquery文本折叠

    /** * Created by dongdong on 2015/4/28. */(function($){ var defaults = { height:40, //文本收起后的高度 speed ...

  8. windows phone 之手势识别(Manipulation)

    在Windows Phone 7的多触摸屏上可以检测到至少四根同时存在的手指,并且一起操作使触摸屏充分发挥效果. 在silverlight开发中通过事件来实现触屏事件的检测,包括低级别的和高级别的接口 ...

  9. Python中使用中文

    python的中文问题一直是困扰新手的头疼问题,这篇文章将给你详细地讲解一下这方面的知识.当然,几乎可以确定的是,在将来的版本中,python会彻底解决此问题,不用我们这么麻烦了. 先来看看pytho ...

  10. WPF之 XAML集合项简单演示

    我们直接通过xaml文件演示一个简单的xaml集合项: <Window x:Class="WPF_XAML集合项.MainWindow" xmlns="http:/ ...