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 ...
随机推荐
- EL简介
一.EL简介 1.语法结构 ${expression}2.[]与.运算符 EL 提供.和[]两种运算符来存取数据. 当要存取的属性名称中包含一些特殊字符,如.或?等并非字母或数字的符 ...
- 9. Linux远程登录
1. 检查网络是否通畅 C:\Users\cfm>ping 192.168.232.131 正在 Ping 192.168.232.131 具有 32 字节的数据:来自 192.168.232. ...
- sql 分组查询及格不及格人数
select score as 类别,count(*) as 人数 from (select case when fen>=60 then '及格' else '不及格' end as scor ...
- 初始化成员列表 ——— 类的const成员和引用成员的初始化
class A { public: A(){}; const int num; CString& s; } A::A() { cout<<A con<<endl; } ...
- kindeditor-4.1.7应用
页面: <script type="text/javascript" src="include/kindeditor/kindeditor.js"> ...
- SQLite事务管理
事务管理对数据库一致性是至关重要的.数据库实现ACID属性以确保一致性.SQLite依赖于本地文件锁和页日志来实现ACID属性.SQLite只支持扁平事务,并不支持事务嵌套和保存点能力. 1.1 事务 ...
- 64位系统上使用PLSQL Dervloper解决方案
win7+64位+Oracle+11g+64位下使用PLSQL+Developer+的解决办法 2012-04-15 01:28:37| 分类: 默认分类 | 标签: |字号大中小 订阅 . w ...
- CSS+HTML网页设计与布局(学习笔记1)
1.在宽度未知时,使div块居中,可以添加以下属性: display:table;margin:0 auto;
- linux部分命令
打包ROOT文件夹tar -cvf ROOT3.tar ./ROOT 解压则相反 ps aux | grep tomcat 直接杀死tomcat sudo kill -9 进程号 rm -rf ./R ...
- weed-fs参数列表
weed-fs没有详细的帮助文档,为了方便阅读,特意把有用的参数帮助罗列出来.未列出的两个命令为version(版本查询) 及shell(这个命令在0.45版本只有回显功能)nerc@Ubuntu:~ ...