poj 1080 dp如同LCS问题
题目链接: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问题的更多相关文章
- poj 1080 基因组(LCS)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19376 Accepted: ...
- poj 1080 dp
基因配对 给出俩基因链和配对的值 求配对值得最大值 简单dp #include<iostream> #include<stdio.h> #include<string ...
- poj 1080 zoj 1027(最长公共子序列变种)
http://poj.org/problem?id=1080 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=27 /* zoj ...
- 【POJ 1080】 Human Gene Functions
[POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...
- Poj 1936,3302 Subsequence(LCS)
一.Description(3302) Given a string s of length n, a subsequence of it, is defined as another string ...
- POJ 1080:Human Gene Functions LCS经典DP
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18007 Accepted: ...
- POJ 1080( LCS变形)
题目链接: http://poj.org/problem?id=1080 Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K ...
- hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)
题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...
- dp poj 1080 Human Gene Functions
题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...
随机推荐
- 【AngularJS】——0.分析
[引导分析]1.什么是AngularJS? 2.为什么要使用它? 3.应用场合? 4.基本思想? 5.四大核心特征? 6.优缺点是什么? 1.定义:AngularJS是一个用于设计动态web应用的前端 ...
- Git命令详解【2】
git的工作区 git 安装 sudo apt-get insall git 查看git 版本 git --version git的配置 #配置用户名 git config --global ...
- HUST 4681 String (DP LCS变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4681 题目大意:给定三个字符串A,B,C 求最长的串D,要求(1)D是A的字序列 (2)D是B的子序列 ...
- [LeetCode OJ] Roman to Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- 将requirejs进行到底(2)
前一篇:JS模块化工具requirejs教程(一):初识requirejs 我们以非常简单的方式引入了requirejs,这一篇将讲述一下requirejs中的一些基本知识,包括API使用方式等. 基 ...
- 5shift shell
echo offcopy %systemroot%\system32\taskmgr.exe %systemroot%\system32\sethc.execopy %systemroot%\syst ...
- WPF RadioButton & CheckBox Style
<Style TargetType="CheckBox"> <Setter Property="Template"> <Sette ...
- iOS: 学习笔记, Swift运算符定义
Swift操作符可以自行定义, 只需要加上简单的标志符即可. @infix 中置运算. 如+,-,*,/运算 @prefix 前置运算. 如- @postfix 后置运算. a++, a-- @ass ...
- C# 数据结构 线性表(顺序表 链表 IList 数组)
线性表 线性表是最简单.最基本.最常用的数据结构.数据元素 1 对 1的关系,这种关系是位置关系. 特点 (1)第一个元素和最后一个元素前后是没有数据元素,线性表中剩下的元素是近邻的,前后都有元素. ...
- ruby特性
1. ruby类结构 每个类都是Class类的对象 所有类都继承自BasicObject类(Module类不能实例化) 2. 单例方法 单例方法可以不定义在类中,只为某个对象定义方法,所以称为单例方法 ...