HDU 1560 - DNA sequence
来源:互联网 发布:开源 量化交易软件 编辑:程序博客网 时间:2024/05/21 07:54
E - DNA sequence
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uAppoint description:
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.
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
14ACGTATGCCGTTCAGT
Sample Output
8
IDA*,temp[]记录每个字符串搜索到第几位
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <string>using namespace std;#define N 10struct node{ int len; string s;}a[N];int n;int pos[N],depth,ans;char dna[]="ACGT";int calen(int *s){ int m=0; for (int i=0;i<n;i++) m=max(m,a[i].len-s[i]); return m;}bool dfs(int *s,int now){ if (now+calen(s)>depth) return false; if (calen(s)==0) return true; int temp[N]; for (int i=0;i<4;i++){ bool flag=false; memcpy(temp,s,sizeof(temp)); for (int j=0;j<n;j++){ if (a[j].s[temp[j]]==dna[i]){ flag=true; temp[j]++; } } if (flag){ if (dfs(temp,now+1)) return true; } } return false;}int main(){ int t; scanf("%d",&t); while (t--){ scanf("%d",&n); for (int i=0;i<n;i++){ cin>>a[i].s; a[i].len=a[i].s.length(); } memset(pos,0,sizeof(pos)); depth=1; while (1){ if (dfs(pos,0)) break; depth++; } printf("%d\n",depth); } return 0;}
0 0
- HDU - 1560 DNA sequence
- HDU-1560 DNA sequence
- HDU 1560DNA sequence
- HDU 1560 - DNA sequence
- HDU - 1560----DNA sequence
- HDU - 1560----DNA sequence
- HDU 1560 DNA sequence IDA*
- hdu 1560 DNA sequence(IDA*)
- HDU 1560 DNA sequence(IDA*~)
- HDU 1560 DNA sequence IDA*搜索
- HDU 1560 DNA sequence hh大神代码
- hdu 1560 DNA sequence (IDA*)
- 【搜索进阶】HDU 1560 DNA sequence
- HDU-1560 DNA sequence(IDA*)
- hdu 1560 DNA sequence(IDA*)
- HDU 1560 DNA sequence(BFS+hash)
- HDU 1560 DNA sequence(IDA*搜索)
- HDU 1560 DNA sequence(状压+搜索)
- [置顶]【源】从零自学Hadoop系列索引
- SpringMVC接收json数据中的一些问题(415错误的解决)
- android 基础知识点(面试准备)
- Unity Flat Shading实现低多边形(low-poly)效果
- 逆波兰表达式题解
- HDU 1560 - DNA sequence
- Android: 调用LayoutInflater方法时warning和exception
- 正则表达式简单用法
- HMM学习笔记—002--维特比算法(viterbi algorithm)
- js判断数据类型
- android 富文本SpannableString去掉下划线
- Android declare-styleable:自定义控件的属性
- QuickLook(实战)
- 为ViewPager添加选项卡导航栏