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. 利用jQuery和Ajax实现检测用户名是否已经被注册

    这是一个jQuery和Ajax的很基础的应用,是我出去面试时的一个面试题.当时脑子有点懵想了好久才知道该怎么去实现,现在回来再看了下书好好总结一下这个东西. 首先新建一个html文件,只有简单的几行代 ...

  2. 货币单位类RmbUnit

    import java.math.BigDecimal; public enum RmbUnit { FEN{ public String toFen(String amt) { BigDecimal ...

  3. django model 中class meta

    class Meta: ordering = ['-num', 'length'] verbose_name = 'name' verbose_name_plural = 'names' orderi ...

  4. 华为OJ题目:刷题

    题目描述: 新入职华为的小伙伴们都有在oj上面刷题的任务,共需要刷100道初级题,45道中级题,5道高级题,其中,做出来的高级题如果超标可以当初级或者中级题,做出来的中级题如果超标可以当初级题.每天, ...

  5. loadrunner负载测试实例

    回想起第一次做性能测试,感慨万千,故写下本文,从:设置虚拟用户,设置场景以及分析运行结果三个方面进行阐述 硬件环境:硬盘 1TG,cpu 3.40GHz,内存4G 软件环境:IE9.0,Weblogi ...

  6. 纸上谈兵:堆(heap)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 堆(heap)又被为优先队列(priority queue).尽管名为优先队列,但 ...

  7. PYTHON入门知识

    基本数据类型 注:查看对象相关成员 var,type,dir 一.整数 如: 18.73.84 每一个整数都具备如下功能: class int(object): """ ...

  8. java集合类(二)

    第十六天知识点总结 一.泛型 泛型:java jdk 1.5 新特性. 泛型的好处: 1.运行时的错误提前到编译时. 2.避免无谓的强制类型转换 自定义方法泛型:自定义泛型就是一个数据类型的占位或一个 ...

  9. js/json 数组的操作

    1.数组的创建 var arrayObj = new Array(); //创建一个数组 var arrayObj = new Array([size]); //创建一个数组并指定长度,注意不是上限, ...

  10. js数组合并

    // 第一种 var mergeTo = [4,5,6], mergeFrom = [7,8,9]; mergeTo = mergeTo.concat(mergeFrom); mergeTo; // ...