题目链接: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. WPF 带CheckBox、图标的TreeView

    WPF 带CheckBox.图标的TreeView 在WPF实际项目开发的时候,经常会用到带CheckBox的TreeView,虽然微软在WPF的TreeView中没有提供该功能,但是微软在WPF中提 ...

  2. ACM YTU 挑战编程 字符串 Problem A: WERTYU

    Problem A: WERTYU Description A common typing error is to place yourhands on the keyboard one row to ...

  3. PHP设计模式之:工厂模式

    工厂模式: 由工厂类根据参数来决定创建出哪一种产品类的实例: 工厂类是指包含了一个专门用来创建其他对象的方法的类.所谓按需分配,传入参数进行选择,返回具体的类.工厂模式的最主要作用就是对象创建的封装. ...

  4. Android Studio 中解决.9图片报错的问题

  5. ecshop---京东手机模板js的eval产生冲突的解决方法。

    今天弄ecshop手机模板的时候,发现首页的广告图出不来,js报错

  6. Python 学习之urllib模块---用于发送网络请求,获取数据

    1.urllib urllib是Python标准库的一部分,包含urllib.request,urllib.error,urllib.parse,urlli.robotparser四个子模块. (1) ...

  7. Meditation Guide

    Meditation “Stop!!!” don’t we just scream[vi. 尖叫:呼啸:发出尖锐刺耳的声音:令人触目惊心 ] this in our minds when the da ...

  8. highcharts-Highmaps 动态传入城市名称

    做前端按地区(地图)分布监控数据展示用了 HIGHMAPS JAVASCRIPT MAPS 控件,很好很强大. 基础实现是这样的:调用插件动态传入需要展示的数据(data),插件会在地图数据(mapd ...

  9. Python学习 - 简单抓取页面

    最近想做一个小web应用,就是把豆瓣读书和亚马逊等写有书评的网站上关于某本书的打分记录下来,这样自己买书的时候当作参考. 这篇日志这是以豆瓣网为例,只讨论简单的功能. 向服务器发送查询请求 这很好处理 ...

  10. WPF 核心体系结构

    WPF 体系结构 主题提供 Windows Presentation Foundation (WPF) 类层次结构,涵盖了 WPF 的大部分主要子系统,并描述它们是如何交互的. System.Obje ...