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. 温习排序算法(基于C指针)

    以前学过的数据结构课,貌似已经忘得一干二净了,偶然又翻起,书中最后一章详细介绍了7种排序算法,现在对其中4种做个总结.(为啥只总结4种,当然是因为偷懒,只想总结简单又常用的!) 先贴一张排序分类图: ...

  2. 接口测试工具-Jmeter使用笔记(八:模拟OAuth2.0协议简化模式的请求)

    背景 博主的主要工作是测试API,目前已经用Jmeter+Jenkins实现了项目中的接口自动化测试流程.但是马上要接手的项目,API应用的是OAuth2.0协议授权,并且采用的是简化模式(impli ...

  3. Docker Machine批量安装docker host

    Dokcer Machine Docker Machine 可以批量安装和配置 docker host   提高docker的安装效率   同时减少人工安装操作的失误 [root@localhost ...

  4. java.lang.IllegalStateException: Connection pool shut down

    最近使用HttpClient 4.5 使用 CloseableHttpClient 发起连接后,使用CloseableHttpResponse 接受返回结果,结果就报错了,上网查了下,有位stacko ...

  5. vue cli 3.0创建项目

    .npm i -g @vue/cli .vue create my-project 此处有两个选择: 1.default (babel, eslint)默认套餐,提供babel和eslint支持 2. ...

  6. 【Mac】-NO.161.Mac.1 -【MacOS 中环境变量设置 zsh: command not found: xxx】

    Style:Mac Series:Java Since:2018-09-10 End:2018-09-10 Total Hours:1 Degree Of Diffculty:5 Degree Of ...

  7. 【LeetCode每天一题】Edit Distance(编辑距离)

    Given two words word1 and word2, find the minimum number of operations required to convert word1 to  ...

  8. canal mysql slave

    [mysqld] log-bin=mysql-bin #添加这一行就ok binlog-format=ROW #选择row模式 server_id=1 #配置mysql replaction需要定义, ...

  9. get请求02

    import requests r = requests.get("http://www.baidu.com") print(r.status_code) #状态码 print(r ...

  10. dedecms二次开发

    安装遇到的问题 修改文件如下 1.date目录下的config.cache.bak.php改成config.cache.php 2install目录下的index.html.install_lock. ...