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.

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

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

CN

Output - 输出

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

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

CN

Sample Input - 输入样例

  1. 1
  2. 4
  3. ACGT
  4. ATGC
  5. CGTT
  6. CAGT

Sample Output - 输出样例

  1. 8

题解

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

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

  1. 1
  2. 4
  3. AAAA
  4. CCCC
  5. GGGG
  6. TTTT

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

  横着看有问题,竖着看?

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

代码 C++

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. int maxDeep, n, data[][];
  5. int vle(int(&siz)[][]) {
  6. int i, j, opt, len[];
  7. memset(len, , sizeof len);
  8. for (i = ; i < n; ++i) {
  9. for (j = ; j < ; ++j) len[j] = std::max(len[j], siz[i][j]);
  10. }
  11. for (i = opt = ; i < ; opt += len[i++]);
  12. return opt;
  13. }
  14. int DFS(int deep, int(&preW)[], int(&preSiz)[][]) {
  15. int i = vle(preSiz), j, w[], siz[][], isFid;
  16. if (!i) return ;
  17. if (i + deep > maxDeep) return ;
  18. for (i = ; i < ; ++i) {
  19. memcpy(w, preW, sizeof w); memcpy(siz, preSiz, sizeof siz);
  20. for (j = isFid = ; j < n; ++j) {
  21. if (data[j][w[j]] == i) {
  22. isFid = ++w[j]; --siz[j][i];
  23. }
  24. }
  25. if (isFid && DFS(deep + , w, siz)) return ;
  26. }
  27. return ;
  28. }
  29. int main() {
  30. int t, i, j, mp[], w[], siz[][];
  31. mp['A'] = ; mp['C'] = ; mp['G'] = ; mp['T'] = ;
  32. memset(w, , sizeof w);
  33. char str[];
  34. scanf("%d", &t);
  35. while (t--) {
  36. memset(data, , sizeof data); memset(siz, , sizeof siz);
  37. scanf("%d ", &n);
  38. for (i = ; i < n; ++i) {
  39. gets(str);
  40. for (j = ; str[j]; ++j) ++siz[i][data[i][j] = mp[str[j]]];
  41. }
  42. for (maxDeep = vle(siz); !DFS(, w, siz); ++maxDeep);
  43. printf("%d\n", maxDeep);
  44. }
  45. return ;
  46. }

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. 批量将PowerDesigner中表字段由小写变成大写

    通过以下VB脚本即可批量修改,在Tools=>Execute Commands下的Edit/Run Scripts,或者通过Ctrl+Shift+X运行以下脚本即可: '************ ...

  2. 好用的一些 git 命令

    git stash  将已修改未提交的 改动保存起来   恢复用git stash pop gir revert  反转commit git rebase 更换基础分支 git grep  -n 显示 ...

  3. Azure基础(三)- Azure的物理架构和服务保证

    Azure fundamentals - Core Cloud Services - Azure architecture and service guarantees Azure provides ...

  4. [LeetCode] 55. Jump Game_ Medium tag: Dynamic Programming

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  5. LeetCode 15 输入无序、有重复,输出排重版 3-Sum

    V1 粗暴的遍历,时间复杂度O(N³) func threeSumClosest(nums []int, target int) int { min := 0 result := 0 for i := ...

  6. git删除和提交

    //删除git分支git branch -D BranchNamegit branch -r -D origin/BranchNamegit push origin -d BranchName//提交 ...

  7. Shadow DOM及自定义标签

    参考链接:点我 一.什么是Shadow DOM Shadow DOM,直接翻译的话就是 影子 DOM,可以理解为潜藏在 DOM 结构中并且我们无法直接控制操纵的 DOM 结构.类似于下面这种结构 Sh ...

  8. asp.net无限递归

    private void button1_Click(object sender, EventArgs e) { DialogResult dialogResult = folderBrowserDi ...

  9. MySql 版本

    MySql 版本: netformwork 2.0 netformwork 4.0

  10. ASP.NET MVC案例教程(六)

    ASP.NET六 一个小难题 我们继续完善“MVC公告发布系统”,这次,我们的需求是对公告发布功能添加日志记录能力,即在发布公告前,记录一次,在公告发布成功后,再记录一次.然后还要使得其具备异常处理, ...