POJ1080 Human Gene Functions 动态规划 LCS的变形
题意读了半年,唉,给你两串字符,然后长度不同,你能够用‘-’把它们补成同样长度,补在哪里取决于得分,它会给你一个得分表,问你最大得分
跟LCS非常像的DP数组 dp[i][j]表示第一个字符串取第i个元素第二个字符串取第三个元素,然后再预处理一个得分表加上就可以
得分表:
score['A']['A'] = score['C']['C'] = score['G']['G'] = score['T']['T'] = 5; score['A']['C'] = score['C']['A'] = -1;
score['A']['G'] = score['G']['A'] = -2;
score['A']['T'] = score['T']['A'] = -1;
score['A']['-'] = score['-']['A'] = -3;
score['C']['G'] = score['G']['C'] = -3;
score['C']['T'] = score['T']['C'] = -2;
score['C']['-'] = score['-']['C'] = -4;
score['G']['T'] = score['T']['G'] = -2;
score['G']['-'] = score['-']['G'] = -2;
score['T']['-'] = score['-']['T'] = -1; score['-']['-'] = -inf;
那么DP方程就好推了:
dp[i][j] = :
dp[i-1][j] + score[s1[i-1]]['-']或者
dp[i][j-1] + score['-'][s2[j-1]]或者
dp[i-1][j-1] + score[s1[i-1]][s2[j-1]]或者
这三者之中取最大的
然后就是边界问题我给忘记了
不够细心,若单单是i==0或者j==0,边界问题就出现了,边界不可能为0的,所以还得处理一下边界
#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<memory.h>
#include<set>
#include<cctype> #define ll long long #define LL __int64 #define eps 1e-8 #define inf 0xfffffff //const LL INF = 1LL<<61; using namespace std; //vector<pair<int,int> > G;
//typedef pair<int,int > P;
//vector<pair<int,int> > ::iterator iter;
//
//map<ll,int >mp;
//map<ll,int >::iterator p; const int N = 1000 + 5; int dp[N][N];
int score[200][200]; void init() {
score['A']['A'] = score['C']['C'] = score['G']['G'] = score['T']['T'] = 5; score['A']['C'] = score['C']['A'] = -1;
score['A']['G'] = score['G']['A'] = -2;
score['A']['T'] = score['T']['A'] = -1;
score['A']['-'] = score['-']['A'] = -3;
score['C']['G'] = score['G']['C'] = -3;
score['C']['T'] = score['T']['C'] = -2;
score['C']['-'] = score['-']['C'] = -4;
score['G']['T'] = score['T']['G'] = -2;
score['G']['-'] = score['-']['G'] = -2;
score['T']['-'] = score['-']['T'] = -1; score['-']['-'] = -inf;
} int main () {
init();
int t;
char s1[N];
char s2[N];
scanf("%d",&t);
while(t--) {
int n,m;
memset(dp,0,sizeof(dp));
scanf("%d %s",&n,s1);
scanf("%d %s",&m,s2);
for(int i=1;i<=n;i++)
dp[i][0] = dp[i-1][0] + score[s1[i-1]]['-'];//边界处理
for(int j=1;j<=m;j++)
dp[0][j] = dp[0][j-1] + score['-'][s2[j-1]];//边界处理
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
int t1 = dp[i-1][j] + score[s1[i-1]]['-'];
int t2 = dp[i][j-1] + score['-'][s2[j-1]];
int t3 = dp[i-1][j-1] + score[s1[i-1]][s2[j-1]];
int maxn = max(t1,t2);
dp[i][j] = max(maxn,t3);
}
}
printf("%d\n",dp[n][m]);
}
return 0;
}
POJ1080 Human Gene Functions 动态规划 LCS的变形的更多相关文章
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- poj1080 - Human Gene Functions (dp)
题面 It is well known that a human gene can be considered as a sequence, consisting of four nucleotide ...
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
- POJ1080 Human Gene Functions(LCS)
题目链接. 分析: 和 LCS 差不多. #include <iostream> #include <cstdio> #include <cstdlib> #inc ...
- POJ-1080 Human Gene Functions---类似LCS
题目链接: https://cn.vjudge.net/problem/POJ-1080 题目大意: 给定两组序列,要你求出它们的最大相似度,每个字母与其他字母或自身和空格对应都有一个打分,求在这两个 ...
- poj1080--Human Gene Functions(dp:LCS变形)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17206 Accepted: ...
- POJ 1080:Human Gene Functions LCS经典DP
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18007 Accepted: ...
- hdu1080 Human Gene Functions() 2016-05-24 14:43 65人阅读 评论(0) 收藏
Human Gene Functions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- Human Gene Functions
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18053 Accepted: 1004 ...
随机推荐
- hdu1561(树形背包)
给定n,m表示n个城堡,我们可以选择攻占m个城堡.要使得价值最大 接下来n行 a b, 第i行的a b,表示攻占第i个城堡的价值为b,但需要先攻占第a个城堡 如果有多个a=0的点,那么就不是一棵树 ...
- Windows Phone开发(7):当好总舵主
原文:Windows Phone开发(7):当好总舵主 吹完了页面有关的话题,今天我们来聊一下页面之间是如何导航的,在更多情况下,我们的应用程序不会只有一个页面的,应该会有N个,就像我们做桌面应 用开 ...
- BDB (Berkeley DB)简要数据库(转载)
使用最近DBD.然后搜了下相关资料,首先公布的是一门科学: 转会http://www.javaeye.com/topic/202990 DB综述DB最初开发的目的是以新的HASH訪问算法来取代旧的hs ...
- uva 11427 - Expect the Expected(概率)
题目链接:uva 11427 - Expect the Expected 题目大意:你每天晚上都会玩纸牌,每天固定最多玩n盘,每盘胜利的概率为p,你是一个固执的人,每天一定要保证胜局的比例大于p才会结 ...
- VMware vSphere 服务器虚拟化之十六 桌面虚拟化之VMware Horizon View
VMware vSphere服务器虚拟化之十六 桌面虚拟化之VMware Horizon View VMware Horizon View (原VMware View的升级版现在版本5.2)是 ...
- AIX 7.1 install python
周围环境AIX7.1 设备python-2.6.2 因为互联网是非常多的安装文档.而且也没有细挑的版本号.因为我觉得python2.6 可能相对保守一些,至少之前用到的版本号是这个.所以此处依旧 ...
- poj1163The Triangle(简单DP)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...
- 找呀志_java网络编程(5)TCP和udp差额
1.TCP定向链接,尽管该网络的不稳定性质,所述不安全确定多少次握手不能保证连接的可靠性.但TCP的三次握手至少(事实上确保了相当大的程度)以确保连接的可靠性; 和UDP不面向连接的,UDP前传送的数 ...
- C# 5.0 Async函数的提示和技巧
一.创建Async函数 Async是C# 5.0中新增的关键字,通过语法糖的形式简化异步编程,它有如下三种方式: async Task<T> MyReturningMethod { ret ...
- 得到View Frustum的6飞机
笔者:i_dovelemon 资源:CSDN 日期:2014 / 9 / 30 主题:View Frustum, Plane, View Matrix, Perspective Projection ...