HDU 1560 迭代加深 解题报告
来源:互联网 发布:gcr.io 阿里云 编辑:程序博客网 时间:2024/06/06 11:01
DNA sequence
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
代码如下:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define max(a,b) ((a)>(b)?(a):(b))#define min(a,b) ((a)<(b)?(a):(b))char str[10][10];int t,n,deep;int ans;char DNA[4]={'A','T','C','G'}; void dfs(int index,int len[]){ if(index>deep) return; int maxx=0; for(int i=0;i<n;++i) maxx=max(strlen(str[i])-len[i],maxx); if(maxx==0) { ans=index; return; } if(index+maxx>deep) return; for(int i=0;i<4;++i) { int flag=0; int pos[10]; for(int j=0;j<n;++j) { if(str[j][len[j]]==DNA[i]) { flag=1; pos[j]=len[j]+1; } else pos[j]=len[j]; } if(flag) dfs(index+1,pos); if(ans!=-1) return; } }int main(){ for(scanf("%d",&t);t;--t) { deep=0; scanf("%d",&n); for(int i=0;i<n;++i) { scanf("%s",str[i]); deep=max(deep,strlen(str[i])); } ans=-1; int pos[10]={0}; while(1) { dfs(0,pos); if(ans!=-1) break; ++deep; //加深迭代 } printf("%d\n",ans); }}
- HDU 1560 迭代加深 解题报告
- Hdu 1560 解题报告 迭代加深搜索
- CodeVS 1288 迭代加深 解题报告
- HDU 1560 迭代加深
- HDU 1560 IDA*(迭代加深搜索)
- 一中OJ #1193 倒水问题[1] | IDDFS-迭代加深 + 二分猜答案 | 解题报告
- hdu 1560 DNA sequence(迭代加深搜索)
- HDU-#1560 DNA sequence(迭代加深搜)
- hdu 1560 IdA* 迭代加深A星搜索
- hdu 1560 DNA sequence(迭代加深搜索)(经典题)
- hdu 1560 DNA sequence(迭代加深搜索)
- 深度优先搜索 迭代加深搜索 hdu 1560
- hdu 2485 迭代加深搜索
- 【sgu510】迭代加深
- 迭代加深+剪枝
- 迭代加深
- 迭代加深搜索
- 迭代加深
- 1082 与7无关的数
- 鞋狗
- POJ3253 Huffman Tree
- 【数据结构笔记】9:两个最小生成树算法注解
- EXT2文件系统笔记之ext2_fill_super
- HDU 1560 迭代加深 解题报告
- ACM整数性问题(nefu115和hdu2099)
- POJ1125 Floyd
- 滕王阁序---王勃
- 迭代器模式
- hdu 1576 A/B 求逆元模板题
- Android应用开发-学生信息管理系统
- C++中#define中的#与##作用和区别
- 测试sklearn包中常用的机器学习算法