Human Gene Functions

题意:

LCS:

设dp[i][j]为前i,j的最长公共序列长度;

dp[i][j] = dp[i-1][j-1]+1;(a[i] == b[j])

dp[i][j] = max(dp[i][j-1],dp[i-1][j]);

边界:dp[0][j] = 0(j<b.size) ,dp[i][0] = 0(i< a.size);

LCS变形:

设dp[i][j]为前i,j的最大价值:

value(x, y)为比较价值;

dp[i][j] = max(dp[i-1][j-1] + value(a[i],b[i]),dp[i][j-1] + value('-', b[i]), dp[i-1][j] + value(a[i],'-');

边界:dp[i][0] = dp[i-1][0] + value(a[i],'-'),(i<=a.size);      dp[0][j] = dp[0][j-1] + value('-',b[i]), (j <= b.size);

边界是个大问题!!

a[i]跟dp[i]的关系搞错.跪了整整一个小时啊!!!

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std ;
#define N 105 const double PI = acos(-1.0);
typedef long long LL ;
char a[N],b[N];
int dp[N][N]; int value(char x, char y){
if(x == y)return ;
else if((x == 'A'&&y == 'C')||(x == 'C'&&y == 'A'))return -;
else if((x == 'A'&&y == 'G')||(x == 'G'&&y == 'A'))return -;
else if((x == 'A'&&y == 'T')||(x == 'T'&&y == 'A'))return -;
else if((x == 'C'&&y == 'G')||(x == 'G'&&y == 'C'))return -;
else if((x == 'C'&&y == 'T')||(x == 'T'&&y == 'C'))return -;
else if((x == 'T'&&y == 'G')||(x == 'G'&&y == 'T'))return -;
else if((x == 'A'&&y == '-')||(x == '-'&&y == 'A'))return -;
else if((x == 'C'&&y == '-')||(x == '-'&&y == 'C'))return -;
else if((x == 'G'&&y == '-')||(x == '-'&&y == 'G'))return -;
else if((x == 'T'&&y == '-')||(x == '-'&&y == 'T'))return -;
else return ;
}
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,aL,bL;
cin>>n;
while(n--){
cin>>aL;
scanf("%s",a);
cin>>bL;
scanf("%s",b);
dp[][] = ;
for(int i = ;i < aL; i++) {dp[i+][] = dp[i][] + value(a[i],'-');}
for(int i = ;i < bL; i++) {dp[][i+] = dp[][i] + value(b[i],'-');}
for(int i = ;i <= aL; i++){
for(int j = ;j <= bL; j++){
if(a[i-] == b[j-]) dp[i][j] = dp[i-][j-] + value(a[i-], b[j-]);
else dp[i][j] = max(dp[i-][j-]+value(a[i-],b[j-]), max(dp[i][j-]+value('-',b[j-]), dp[i-][j]+value(a[i-],'-')));
}
}
cout<<dp[aL][bL]<<endl;
}
return ;
}

poj 1080 (LCS变形)的更多相关文章

  1. hdu 1080(LCS变形)

    Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  2. POJ 1080( LCS变形)

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

  3. poj 1080 基因组(LCS)

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

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

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

  5. 【POJ 1080】 Human Gene Functions

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

  6. UVA-1625-Color Length(DP LCS变形)

    Color Length(UVA-1625)(DP LCS变形) 题目大意 输入两个长度分别为n,m(<5000)的颜色序列.要求按顺序合成同一个序列,即每次可以把一个序列开头的颜色放到新序列的 ...

  7. poj 1080 dp如同LCS问题

    题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...

  8. poj 1080 Human Gene Functions(lcs,较难)

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

  9. Human Gene Functions POJ 1080 最长公共子序列变形

    Description It is well known that a human gene can be considered as a sequence, consisting of four n ...

随机推荐

  1. 五、selecting with the API

    1. 命令通常从selection list中得到input, 调用MGlobal::getActiveSelectionList(MSelectionList &dest, bool ord ...

  2. window下乌龟git安装和使用

    一.安装git for windows 首先下载git for windows客户端http://msysgit.github.io/ 安装过程没什么特别的,不停next就ok了 图太多就不继续了~~ ...

  3. C++学习基础五之函数参数——形参

    一.理论部分 C++中函数形参主要分为两类,如图1所示, 图1 总结: 一.当函数参数为非引用形参时,传进函数体内的是实参的拷贝,(注意,对于基本类型而言,拷贝的是实参的值,对于指针而言拷贝的是实参的 ...

  4. Maven实战(二)构建简单Maven项目

    上一节讲了maven的安装和配置,这一节我们来学习一下创建一个简单的Maven项目 1. 用Maven 命令创建一个简单的Maven项目 在cmd中运行如下命令: mvn archetype:gene ...

  5. sscanf函数和正则表达式

    看了几篇介绍sscanf函数,真是发现自己好多东西没理解透,详细介绍使用在sscanf中使用正则表达式. 第一篇: 此文所有的实验都是基于下面的程序: char str[10]; for (int i ...

  6. 为什么匿名内部类和局部内部类只能访问final变量

    因为虽然匿名内部类在方法的内部,但实际编译的时候,内部类编译成Outer.Inner,这说明内部类所处的位置和外部类中的方法处在同一个等级上,外部类中的方法中的变量或参数只是方法的局部变量,这些变量或 ...

  7. 关于 this 和 prototype 的理解

    1:this 的理解比较好的书是 <Javascript语言精粹> 平时我们全局写 var a = 1, 其实就是 window.a = 1; var f = function(){},  ...

  8. VC++模态对话框和非模态对话框

    MFC中有两种类型的对话框:模态对话框和非模态对话框.  模态对话框是指当其显示时,程序会暂停执行,直到关闭这个模态对话框后,才能继续执行程序中其他任务.非模态对话框是指当其显示时,允许转而执行程序中 ...

  9. Linux Shell脚本入门--cut命令

    Linux Shell脚本入门--cut命令 cut cut 命令可以从一个文本文件或者文本流中提取文本列. cut语法 [root@www ~]# cut -d'分隔字符' -f fields &l ...

  10. CentOS使用virtualenv搭建独立的Python环境-python虚拟环境

    CentOS使用virtualenv搭建独立的Python环境-python虚拟环境 virtualenv可以搭建虚拟且独立的python环境,可以使每个项目环境与其他项目独立开来,保持环境的干净,解 ...