POJ1080 Human Gene Functions(LCS)
题目链接。
分析:
和 LCS 差不多。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map> using namespace std; const int maxn = ; int G[][] = {
{, -, -, -, -},
{-, , -, -, -},
{-, -, , -, -},
{-, -, -, , -},
{-, -, -, -, }
}; int dp[maxn][maxn]; void trans(char *s, int n) {
for(int i=; i<n; i++) {
switch(s[i]) {
case 'A': s[i] = ; break;
case 'C': s[i] = ; break;
case 'G': s[i] = ; break;
case 'T': s[i] = ; break;
case '-': s[i] = ; break;
}
}
} int main(){
int T, n, m;
// freopen("my.txt", "r", stdin);
char s1[maxn], s2[maxn]; scanf("%d", &T); while(T--) {
scanf("%d%s%d%s", &n, s1, &m, s2);
trans(s1, n); trans(s2, m); dp[][] = ;
for(int i=; i<=m; i++) dp[i][] = G[s2[i-]][] + dp[i-][]; for(int i=; i<=n; i++) dp[][i] = G[s1[i-]][] + dp[][i-]; for(int i=; i<=m; i++) {
for(int j=; j<=n; j++) {
int u = s2[i-], v = s1[j-]; dp[i][j] = dp[i-][j-] + G[u][v];
dp[i][j] = max(dp[i][j], dp[i-][j]+G[u][]);
dp[i][j] = max(dp[i][j], dp[i][j-]+G[v][]);
}
} printf("%d\n", dp[m][n]);
} return ;
}
POJ1080 Human Gene Functions(LCS)的更多相关文章
- POJ 1080:Human Gene Functions LCS经典DP
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18007 Accepted: ...
- poj1080 - Human Gene Functions (dp)
题面 It is well known that a human gene can be considered as a sequence, consisting of four nucleotide ...
- POJ1080 Human Gene Functions 动态规划 LCS的变形
题意读了半年,唉,给你两串字符,然后长度不同,你能够用'-'把它们补成同样长度,补在哪里取决于得分,它会给你一个得分表,问你最大得分 跟LCS非常像的DP数组 dp[i][j]表示第一个字符串取第i个 ...
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 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 ...
- poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17805 Accepted: ...
- 【POJ 1080】 Human Gene Functions
[POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...
- 刷题总结——Human Gene Functions(hdu1080)
题目: Problem Description It is well known that a human gene can be considered as a sequence, consisti ...
随机推荐
- padding与margin的差别
之前一直没有搞懂android:padding和android:layout_margin的差别,事实上概念非常easy,padding是站在父view的角度描写叙述问题,它规定它里面的内容必须与这个 ...
- Android Studio下打jar包
在我们使用Eclipse时,我们常常使用的第三方类库文件大多都是jar包形式,用起来很方便.但是jar包只能打包class文件,对于Android UI类库而言,我们常常需要打包资源文件,对于界面不多 ...
- 《CODE》讲了什么?
本书首先从黑夜中用手电筒开关灯的方式来与小伙伴交流从而引出了编码与组合的概念,并阐明了编码的本质就是交流,是一种用来在机器与人之间传递信息的方式.然后在第 2~3 章中讲述了编码与组合的应用,如电报机 ...
- utils object doesn,t exists中毒后,就删除了.JS文件后台就出现了前面的英文。请问怎么解决
明显是你删了js丢失了函数了...从备份里还原一份.js出来放进去,前台也不能删,如果遇到名字冲突,修改一下名字即可
- cxf WebService整理 (基于注解)
http://blog.csdn.net/zjw10wei321/article/details/39889823
- vsftp 安装日志
很早的一个日志了,从自家的QQ上,查看总不方便,搬家的. 安装完 centos后 安装vsftpd yum install vsftpd 安装伯克利数据库工具 yum install db4 db4- ...
- Ajax的工作流程简述
提到Ajax相信我们都不会陌生,不管你是前端开发还是后台数据处理的程序员,ajax的作用就像现在生活中的手机一样,无论是作用还是流程都差不多,这里我们要进行ajax操作后台数据并显示在页面上的话,首先 ...
- 你好,C++(7)第三部分 C++世界众生相 3.2.1 变量的定义与初始化
第3部分 C++世界众生相 在听过了HelloWorld.exe的自我介绍,完成了与C++世界的第一次亲密接触后,大家是不是都急不可待地想要一试身手,开始编写C++程序了呢?程序的两大任务是描述数据和 ...
- 【USACO 2.1.3】三值的排序
[题目描述] 排序是一种很频繁的计算任务.现在考虑最多只有三值的排序问题.一个实际的例子是,当我们给某项竞赛的优胜者按金银铜牌排序的时候.在这个任务中可能的值只有三种1,2和3.我们用交换的方法把他排 ...
- C++ Primer 5th 第15章 面向对象程序设计
面向对象程序设计的核心思想是:数据抽象.继承和动态绑定. 数据抽象:将类的接口与实现分离: 继承:定义相似类型并对相似关系建模: 动态绑定:一定程度上上忽略相似类型间的区别,用同一方式使用它们. 1. ...