HDU 1560 DNA sequence(DNA序列)

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

 

Problem Description - 题目描述

  The twenty-first century is a biology-technology developing century. We know that a gene is made of DNA. The nucleotide bases from which DNA is built are A(adenine), C(cytosine), G(guanine), and T(thymine). Finding the longest common subsequence between DNA/Protein sequences is one of the basic problems in modern computational molecular biology. But this problem is a little different. Given several DNA sequences, you are asked to make a shortest sequence from them so that each of the given sequence is the subsequence of it.

  For example, given "ACGT","ATGC","CGTT" and "CAGT", you can make a sequence in the following way. It is the shortest but may be not the only one.

二十一世纪是生物技术突飞猛进的世纪。我们知道基因由DNA组成。构建DNA的核苷酸有A(腺嘌呤),C(胞嘧啶),G(鸟嘌呤)和T(胸腺嘧啶)。寻找DNA/蛋白质序列间的最长公共子序列是现代计算分子生物学的基本问题之一。然而这个问题有些许不同。给定若干DNA序列,你需要构建一个最短序列使得给定序列都是都是它的子序列。

比如。给定"ACGT","ATGC","CGTT"和"CAGT",你可以通过如下方式构建一个序列。最短序列不唯一。

CN

Input - 输入

  The first line is the test case number t. Then t test cases follow.

  In each case, the first line is an integer n ( 1<=n<=8 ) represents number of the DNA sequences.

  The following k lines contain the k sequences, one per line. Assuming that the length of any sequence is between 1 and 5.

第一行为测试用例的数量t。随后t个测试用例。
每个用例中第一行为一个整数n ( 1<=n<=8 ) 表示DNA序列的数量。
随后k行,每行一个序列。假定任意序列长度为1到5。

CN

Output - 输出

  For each test case, print a line containing the length of the shortest sequence that can be made from these sequences.

对于每个测试用例,输出一行可构建序列的最短长度。

CN

Sample Input - 输入样例

1
4
ACGT
ATGC
CGTT
CAGT

Sample Output - 输出样例

8

题解

  IDA* = (暴力DFS + 剪枝)*反反复复,所以问题在于怎么剪枝

  如果用剩余待匹配序列的最大长度来剪枝……下面的数据就有问题(虽然HDU上并没有)

1
4
AAAA
CCCC
GGGG
TTTT

  然后秉着不会做就百度的原则(逃

  横着看有问题,竖着看?

  统计每行ACGT的个数,然后在以此求各个ACGT最大的和,依次剪枝就比上面的方法科学多了……

代码 C++

 #include <cstdio>
#include <cstring>
#include <algorithm>
int maxDeep, n, data[][];
int vle(int(&siz)[][]) {
int i, j, opt, len[];
memset(len, , sizeof len);
for (i = ; i < n; ++i) {
for (j = ; j < ; ++j) len[j] = std::max(len[j], siz[i][j]);
}
for (i = opt = ; i < ; opt += len[i++]);
return opt;
}
int DFS(int deep, int(&preW)[], int(&preSiz)[][]) {
int i = vle(preSiz), j, w[], siz[][], isFid;
if (!i) return ;
if (i + deep > maxDeep) return ;
for (i = ; i < ; ++i) {
memcpy(w, preW, sizeof w); memcpy(siz, preSiz, sizeof siz);
for (j = isFid = ; j < n; ++j) {
if (data[j][w[j]] == i) {
isFid = ++w[j]; --siz[j][i];
}
}
if (isFid && DFS(deep + , w, siz)) return ;
}
return ;
}
int main() {
int t, i, j, mp[], w[], siz[][];
mp['A'] = ; mp['C'] = ; mp['G'] = ; mp['T'] = ;
memset(w, , sizeof w);
char str[];
scanf("%d", &t);
while (t--) {
memset(data, , sizeof data); memset(siz, , sizeof siz);
scanf("%d ", &n);
for (i = ; i < n; ++i) {
gets(str);
for (j = ; str[j]; ++j) ++siz[i][data[i][j] = mp[str[j]]];
}
for (maxDeep = vle(siz); !DFS(, w, siz); ++maxDeep);
printf("%d\n", maxDeep);
}
return ;
}

HDU 1560 DNA sequence(DNA序列)的更多相关文章

  1. hdu 6299 Balanced Sequence (括号序列,贪心)

    大意: 记$f(t)$表示字符串$t$的最长括号匹配子序列, 给定n个括号序列, 求它们重排后的最大f(t). 首先可以注意到一个括号序列中已经匹配的可以直接消去, 一定不会影响最优解. 那么这样最终 ...

  2. POJ1699 HDU 1560 Best Sequence(AC自动机 最短路)

    曾写过迭代加深搜索的方法,现在使用在AC自动上跑最短路的方法 dp[i][j]表示状态为到节点i,模式串是否包含的状态为j的最短串的长度,则状态转移方程为: dp[nx][ny] = min(dp[x ...

  3. hdu 1560 DNA sequence(搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1560 DNA sequence Time Limit: 15000/5000 MS (Java/Others)  ...

  4. hdu 1560 DNA sequence(迭代加深搜索)

    DNA sequence Time Limit : 15000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total ...

  5. DNA sequence HDU - 1560

    DNA sequence Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  6. 【HDU - 1560】DNA sequence (dfs+回溯)

    DNA sequence 直接中文了 题目描述 21世纪是生物科技飞速发展的时代.我们都知道基因是由DNA组成的,而DNA的基本组成单位是A,C,G,T.在现代生物分子计算中,如何找到DNA之间的最长 ...

  7. DNA sequence open reading frames (ORFs) | DNA序列的开放阅读框ORF预测

    常见的ORF预测工具 Open Reading Frame Finder- NCBI ORF Finder - SMS OrfPredictor  - YSU 基本概念 开放阅读框(英语:Open r ...

  8. HDU1560 DNA sequence —— IDA*算法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1560 DNA sequence Time Limit: 15000/5000 MS (Java/Oth ...

  9. POJ 2778 DNA Sequence(AC自动机+矩阵加速)

    DNA Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9899   Accepted: 3717 Desc ...

随机推荐

  1. SpringBoot 学习教程(二):示例

    发布方式 构建Jar包,cmd命令行运行Spring Boot程序 第一步:在pom.xml中将packing节点值修改为jar,如下面加粗部分: <groupId>com.example ...

  2. SQL使用之关联更新、批量插入

    使用场景 某个字段数据异常,利用另外一张表同步修改该表异常字段的数据; 关联更新 UPDATE tableName1 AS t1 LEFT JOIN tableName12 AS t2 ON t1.x ...

  3. 微软移除WIN10密码过期政策Microsoft Removes Password-Expiration Policy in Windows 10

    Microsoft this week announced a series of changes to the security baseline in Windows 10, including ...

  4. cocos2d JS 源生js实现each方法

    javascript笔记——源生js实现each方法   出处:http://www.lovejavascript.com/#!zone/blog/content.html?id=48 jquery里 ...

  5. OOA/OOD/OOP

    转载自https://www.cnblogs.com/zzyoucan/p/3576932.html Object-Oriented Analysis:面向对象分析方法 是在一个系统的开发过程中进行了 ...

  6. 北京大学Cousera学习笔记--8-计算导论与C语言基础--C的运算部分

    赋值运算符 1.两边类型不同:赋值时要进行类型转换,右边要转换到左边 2.长数赋值短数 最后的部分截断赋值给短数 3.短数赋给长数 数不变 4.符号位赋值 --计算机不区分符号位数字位,直接赋值 表达 ...

  7. 北京大学Cousera学习笔记--4-计算导论与C语言基础--计算机的基本原理-程序运行的基本原理

    已知:电路能完成计算 怎么计算:设计好很多个原子电路,需要的时候就把他们临时组装在一起--ENIAC 升级:冯诺依曼-EDVAC(现在的计算机都是) 1.通过某种命令来控制计算机.让计算机按照这种命令 ...

  8. spring boot 整合 百度ueditor富文本

    百度的富文本没有提供Java版本的,只给提供了jsp版本,但是呢spring boot 如果是使用内置tomcat启动的话整合jsp是非常困难得,今天小编给大家带来spring boot整合百度富文本 ...

  9. Objective-C RunTime 学习笔记 之 消息转发流程

    1) 当向某个对象发送消息时,先从cache(cache_t)中查找方法对象(method_t),如果找到则进行回调:否则通过查找对象的类(元类)定义中方法列表,一直追溯到NSObject, 如果找到 ...

  10. mysql user表root 用户误删除解决方法

    1:停止mysql服务2:mysql安装目录下找到my.ini;2:找到以下片段[mysqld]4:另起一行加入并保存skip-grant-tables5:启动mysql服务6:登录mysql(无用户 ...