题目链接
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.

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.

Output

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

Sample Input

1
4
ACGT
ATGC
CGTT
CAGT

Sample Output

8

大致题意
输入t,接下来 t 组,输入一个n,表示 n 个DNA,DNA只包含ACGT四个字母,求一个最短序列顺序包含这 n 个字母

具体思路
一开始以为是一道大模拟的题目,WA了好多发,最后发现是深搜减枝,一开始我们求出所有给定的序列最大长度,先假设这些序列所需要的最大顺序序列是maxdeep(所有序列中的最大长度),然后枚举这个情况下的排列ACGT,当出现形成之后无法包含所有的序列,此时maxdeep+1,进行下一轮的深搜枚举,直到在maxdeep的情况下可以顺序包含所有的序列后输出,一味的深搜必然会引起超时,在这里我们就需要剪枝,当深搜的时候,每当枚举一个元素,原序列中可能会有序列的未匹配首字母与其对应,对应之后会剩下还有几个字母,当这些序列的maxnun(最大剩余字母量)加上当前deep(已经匹配的最短序列)之和,大于maxdeep时,则表示我们此时的maxdeep已经无法满足需求,直接减枝进行下一轮的深搜,而当我们maxnum(最大剩余字母量)等于0的时候,则表示已经全部匹配,可以输出d=maxdeep了

#include<bits/stdc++.h>
using namespace std;
char dna[4]= {'A','C','G','T'};
int nowpot[10];
int t,maxdeep,maxlen,n;
struct C
{char import[10];int pot;
} c[10];
int maxnum()
{int sum=0;for (int i=0;i<n;i++){sum=max(sum,c[i].pot-nowpot[i]);}return sum;
}
int dfs(int deep)
{if (deep+maxnum()>maxdeep){return 0;}if (maxnum()==0){return 1;}int now[10];for (int i=0; i<n; i++){now[i]=nowpot[i];}for (int i=0; i<4; i++){int flag=0;for (int j=0; j<n; j++){if (c[j].import[nowpot[j]]==dna[i]){flag=1;nowpot[j]++;}}if (flag==1){if (dfs(deep+1)==1){return 1;}for (int k=0; k<n; k++){nowpot[k]=now[k];}}}return 0;
}
int main()
{scanf("%d",&t);while (t--){maxdeep=maxlen=0;scanf("%d",&n);for (int i=0; i<n; i++){scanf("%s%*c",&c[i].import);c[i].pot=strlen(c[i].import);maxlen=max(maxlen,c[i].pot);nowpot[i]=0;}maxdeep=maxlen;while (true){if (dfs(0)==1){break;}maxdeep++;}printf("%d\n",maxdeep);}return 0;
}

HDU 1560 sequence相关推荐

  1. HDU 1560 DNA sequence(DNA序列)

    HDU 1560 DNA sequence(DNA序列) Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K  ...

  2. HDU - 5919 Sequence II——主席树+区间种类++逆序建树

    [题目描述] HDU - 5919 Sequence II [题目分析] 题目给定一个数组,每次查询一个区间,找出区间内不同数字的个数x,然后输出按出现顺序第x/2向上取整个数字的位置. 按照要求,我 ...

  3. HDU 3397 Sequence operation(线段树)

    HDU 3397 Sequence operation 题目链接 题意:给定一个01序列,有5种操作 0 a b [a.b]区间置为0 1 a b [a,b]区间置为1 2 a b [a,b]区间0变 ...

  4. hdu 3397 Sequence operation(线段树,lazy,区间合并)

    hdu 3397 Sequence operation 线段树lazy和区间合并结合的一个题,相当于几个题集中到一起嘛,分开想就好了 0,1,2操作都要lazy,2的异或操作找到每一只含1或只含0的区 ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1560 题意:从n个串中找出一个最短的公共串,,该公共串对于n个字符串不要求连续,即只要保持相对顺序就好 ...

  6. HDU - 1560 DNA sequence

    给你最多8个长度不超过5的DNA系列,求一个包含所有系列的最短系列. 迭代加深的经典题.(虽然自己第一次写) 定一个长度搜下去,搜不出答案就加深大搜的限制,然后中间加一些玄学的减枝 //Twenty ...

  7. DNA sequence HDU 1560

    写了有段时间搜索题目,但是第一次碰到迭代深搜. 这是题目链接 题目的意思大概就是给你几个字符串让后让你求包含所有这几个字符串的最短字符串.不要求连续只要相对位置不变就可以 这道题我没有用广搜写过,好像 ...

  8. HDU 5919 Sequence II 主席树

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5919 Sequence II Time Limit: 9000/4500 MS (Java/Othe ...

  9. hdu 5312 Sequence(数学推导——三角形数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5312 Sequence Time Limit: 2000/2000 MS (Java/Others)  ...

最新文章

  1. 如何使Git“忘记”已跟踪但现在位于.gitignore中的文件?
  2. leetcode347 - Top K Frequent Elements - medium
  3. 全球及中国食品色素行业供应前景与发展趋势研究报告2022版
  4. AndroidWidget实践 --- EverydayTips开发(6)
  5. 算法题目——电梯(HDU-1008)
  6. Camera摄像头工作原理
  7. python 问题自动匹配解决方案_最好的 Python IDE,你们推荐使用哪一个?
  8. 在 React 中使用 TypeScript
  9. 09-解决服务器被黑上不了网的问题
  10. resizableImageWithCapInsets:方法的探析 (转载笔记)
  11. matlab做南丁格尔玫瑰图,用VBA做个南丁格尔玫瑰图模板!
  12. Java程序员辛勤工作7年被裁,背后的思考与总结
  13. 内大计算机学院马学彬,内蒙古大学 计算机学院 2012-2013(一)课程总表.doc
  14. 幻读与不可重复读区别
  15. ASP.NET程序设计教程(C#版)——学习心得
  16. Qt 圆形进度条实现
  17. 定时循环发送TCP消息(例如:控制设备的开关机等场景)—— 定时执行专家
  18. 基于微信小程序的乐团团购系统设计与实现-计算机毕业设计源码+LW文档
  19. c语言成绩管理系统教程,C语言学生成绩管理系统教程.doc
  20. 易事通人力资源管理软件 v8.1.4 专业版 下载

热门文章

  1. cj20n sap 报错未知列的名称_sap ps模块全称 SAP,PS模块配置和操作手册
  2. html不刷新页面更新js和图片
  3. 微信小程序 请求函数 同步封装方法
  4. debian10.9离线安装haproxy(附离线安装包)
  5. 2022年G1工业锅炉司炉操作证考试题库及模拟考试
  6. 苹果收购AI音乐公司,音乐人工智能将迎来新机遇?
  7. 用阿里云安装docker
  8. 谁是卧底服务器维护,问道手游8.9每周探案谁是卧底答案分享_蚕豆网新闻
  9. LeetCode 518 和LeetCode 377 的比较
  10. 快手直播如何引流?快手直播引流怎么做?快手直播推广如何精准吸粉?​