poj 1080 (LCS变形)
题意:
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变形)的更多相关文章
- hdu 1080(LCS变形)
Human Gene Functions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- POJ 1080( LCS变形)
题目链接: http://poj.org/problem?id=1080 Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K ...
- poj 1080 基因组(LCS)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19376 Accepted: ...
- 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 ...
- UVA-1625-Color Length(DP LCS变形)
Color Length(UVA-1625)(DP LCS变形) 题目大意 输入两个长度分别为n,m(<5000)的颜色序列.要求按顺序合成同一个序列,即每次可以把一个序列开头的颜色放到新序列的 ...
- poj 1080 dp如同LCS问题
题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- Human Gene Functions POJ 1080 最长公共子序列变形
Description It is well known that a human gene can be considered as a sequence, consisting of four n ...
随机推荐
- vmware workstation LINUX磁盘扩容
1.edit virtual machine settings -> 选中硬盘->右侧utilities->expand(虚拟机不能存在镜像),输入要扩容到的大小 2.扩容之后进入系 ...
- READONLY、、cursor、、VARYING
针对 Transact-SQL 过程的准则:所有 Transact-SQL 数据类型都可以用作参数.您可以使用用户定义的表类型创建表值参数.表值参数只能是 INPUT 参数,并且这些参数必须带有 RE ...
- (转)SQLServer_T-SQL 语句执行时间的查询
原文地址:http://blog.csdn.net/wangjunhe/article/details/7211974 --利用getdatedeclare @beginTime datetime d ...
- set JAVA_HOME in RHEL/CentOS
3.3. Install OpenJDK on Red Hat Enterprise Linux Introduction OpenJDK is one of many Java Developmen ...
- RNN神经网络和英中机器翻译的实现
本文系qitta的文章翻译而成,由renzhe0009实现.转载请注明以上信息,谢谢合作. 本文主要讲解以recurrent neural network为主,以及使用Chainer和自然语言处理其中 ...
- js调用java代码返回解决方案
版权声明:本文为楼主原创文章,未经楼主允许不得转载,如要转载请注明来源. 今天封装一个加密标签,遇到一个问题,我需要对页面上的数据调用java后台代码进行解密,而标签里只能通过js获取到数据,所以就遇 ...
- yum install mysql
rpm -qa|grep -i mysqlmysql-libs-5.1.52-1.1.alios6.1.x86_64mysql-5.1.52-1.1.alios6.1.x86_64mysql-deve ...
- oracle中的查询语句(关于出库入库信息表,明细表,把捆包箱表,单位信息表的集中查询)
--查出所有现金中心的单位IDwith AllUnitas(select t.ORGANIZATIONID orgid,t.parentidfrom CDMS_ORGANIZATION t where ...
- 如何实现Qlikview的增量数据加载
笔者备注: 刚刚接错Qlikview,上网搜集的资料,如何处理增量数据. 1 寻找增量时间戳(1)各种数据库:表的创建时间字段和修改时间字段或者最后的修改时间字段:(2)sql server:可以用找 ...
- redis 问题解决(MISCONF Redis is configured to save RDB snapshots)
(error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on d ...