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 ...
随机推荐
- HTML页面嵌入视频和JS控制切换视频的问题
文章摘自:http://www.cnblogs.com/jorton/archive/2012/03/19/vidio_in_site.html 首先,在页面中嵌入视频的HTML代码为: 1 < ...
- 解决GBK字符转UTF-8乱码问题
通过以下方法将GBK字符转成UTF-8编码格式的byte[]数组 package test; import java.io.UnsupportedEncodingException; public c ...
- 框架操作DOM和原生js操作DOM比较
问题引出 对于Angular和React操作DOM的速度,和原生js操作DOM的速度进行了一个比较: 一个同学做的demo 代码如下: <!DOCTYPE html> <html n ...
- 用odbc连接oracle问题
如果用11g的客户端,然后通过odbc(远程连接)连接10g的oracle,会出现监听程序无法启动(ORA-12541: TNS: 无监听程序) 此时需要在客户端目录中D:\instantclient ...
- Python isdigit()方法
描述 Python isdigit() 方法检测字符串是否只由数字组成. 语法 isdigit()方法语法: str.isdigit() 参数 无. 返回值 如果字符串只包含数字则返回 True 否则 ...
- Ninject的使用
摘要 DI容器的一个责任是管理他创建的对象的生命周期.他应该决定什么时候创建一个给定类型的对象,什么时候使用已经存在的对象.他还需要在对象不需要的时候处理对象.Ninject在不同的情况下管理对象的生 ...
- Python 集合方法总结
1.添加一个元素: add(...) Addan element to a set. 1 2 3 4 >>> a = {'shaw',11,22} >>>a. ...
- svn 命令行创建和删除 分支和tags
创建分支 svn cp -m "create branch" http://svn_server/xxx_repository/trunk http://svn_server/xx ...
- .net该的帐
1.web api 2.socket通信 3.NUnit单元测试 4.了解自动化测试各种工具
- oracle命令
oracle创建表空间: 1.如果在PL/SQL 等工具里打开的话,直接修改下面的代码中[斜体加粗部分]执行 2.确保路径存在,比如[D:\oracle\oradata\Oracle9i\]也就是你要 ...