HDU 1506 DNA sequence IDA*
来源:互联网 发布:原油数据影响大吗 编辑:程序博客网 时间:2024/06/05 18:02
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 Sample Output
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.
14ACGTATGCCGTTCAGT
8
迭代加深搜索(IDA*)
#include<iostream>//迭代加深搜索IDA*#include<cstdio>#include<cstring>using namespace std;struct node{ int p[10];//经过迭代产生的长度}temp;int n,len[12];char s[12][12];char DNA[]="ACGT";int DFS(node tt,int ss,int d)//ss为迭代深度d为当前深度{ struct node f; if(ss>d) return 0;//迭代深度超过d int i,j; for(i=0;i<=n-1;i++) { if(len[i]-tt.p[i]+ss>d) return 0;//未迭代的长度加上迭代深度如果大于d返回0 } for(i=0;i<=n-1;i++) { if(tt.p[i]<len[i]) break; } if(i==n) return 1;//全部迭代完成 int flag; for(i=0;i<=3;i++)//匹配ACGT { flag=0; for(j=0;j<=n-1;j++) { if(s[j][tt.p[j]]==DNA[i]) { flag=1;//表示匹配上 f.p[j]=tt.p[j]+1; } else { f.p[j]=tt.p[j]; } } if(flag&&DFS(f,ss+1,d)) return 1;//ss+1,递归迭代下一层 } return 0;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d",&n); int i; for(i=0;i<=n-1;i++) { scanf("%s",s[i]); len[i]=strlen(s[i]); } for(i=0;;i++)//i为迭代加深的深度 if(DFS(temp,0,i)) break;//从ss=0开始迭代搜索,到i结束 printf("%d\n",i);//输出深度,即最短的字符串长度 } return 0;}
阅读全文
0 0
- HDU 1506 DNA sequence IDA*
- HDU 1560 DNA sequence IDA*
- hdu 1560 DNA sequence(IDA*)
- HDU 1560 DNA sequence(IDA*~)
- HDU 1560 DNA sequence IDA*搜索
- hdu 1560 DNA sequence (IDA*)
- HDU-1560 DNA sequence(IDA*)
- hdu 1560 DNA sequence(IDA*)
- HDU 1560 DNA sequence(IDA*搜索)
- hdu oj 1560 DNA sequence(IDA*)
- HDU 1560 DNA sequence(IDA*)
- HDU 1560 DNA sequence(IDA*)
- HDU1560:DNA sequence(IDA*)
- hdu1560 DNA sequence (IDA*)
- HDU1560 DNA sequence (IDA*)
- HDU1560 DNA sequence IDA*
- HDU1560:DNA sequence(IDA星)
- HDU1560 DNA sequence 迭代深搜IDA*
- 网站开发的一般流程
- HTTP传值方式和请求方式/angular的请求方式
- HTTP工作流程
- tar
- SAP报表报错CX_SY_ARITHMETIC_OVERFLOW
- HDU 1506 DNA sequence IDA*
- 数据库三大范式(第一范式,第二范式,第三范式)
- 【noip2011D2T1】计算系数(数论)
- 二分搜索
- Glide 一个专注于平滑滚动的图片加载和缓存库
- struts2应用02
- python 字符串翻转| 单词翻转
- 学习下oracle的存储过程增删改查操作以及java调用存储过程
- 数据泵+DBLINK迁移用户