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. 点击按钮如何改变当前窗口的url

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. React之ref

    作为响应式开发框架React,我们知道他是数据驱动的,但有时候避免不了还是得动用到DOM操作,这个时候我们就可以用到ref:用法如下: 然后这样做有个弊端,当一个 ul 下面的 li 是动态添加的时候 ...

  3. 【托业】【全真题库】TEST3-语法题

    101. sales representative 销售代表 keep one's promise with 遵守对……的诺言,信守对……的承诺 107. express interest in 表现 ...

  4. 2019年IntelliJ IDEA 最新注册码,亲测可用(截止到2020年3月11日)

    2019年IntelliJ IDEA 最新注册码(截止到2020年3月11日) 操作步骤: 第一步:  修改 hosts 文件 ~~~ 在hosts文件中,添加以下映射关系: 0.0.0.0 acco ...

  5. turtle模块绘图

    import turtle #运动命令 # forward(d) 向前移动d长度 # backward(d) 向后移动d长度 # right(d) 向右转动多少度 #left(d) 向左转动多少度 # ...

  6. dubbo搭建

    1.安装java : yum install java 2.下载Tomcat: wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-9/v9.0.1 ...

  7. php curl 上传json数据

    PUT $data = array('username'=>'dog','password'=>'tall'); $data_json = json_encode($data); $ch ...

  8. flask error

    from flask import Flaskfrom flask import abort app = Flask(__name__) @app.route('/')def index(): ret ...

  9. c# webapi上传、读取、删除图片

    public class FileAPIController : BaseController    {        private readonly string prefix = "t ...

  10. spring boot jpa 整合

    1,Eclipse JPA Tool配置 https://www.cnblogs.com/wgslucky/p/10109300.html 2,项目地址 https://gitee.com/wgslu ...