DNA sequence HDU - 1560 迭代深搜加剪枝

问题:

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

题意:给你n个字符串,让这n个字符串组成一个最短的公共字符串,题目样例图更易懂。

思路:迭代搜索,从n个字符串中最长的字符串开始搜,一点点的增加,直到找到最佳的答案为止。

代码如下:

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define eps 1e-9
#define lowbit(x) x&(-x)
#define PI acos(-1.0)
#define N 11
char to[4]= {'A','C','G','T'},s[N][N];
int t,n,pos[N],dep,ans,len[N];
void dfs(int x,int pos[])
{
    if(x>dep)return ;//当前长度都已经大于预测长度则返回
    int maxx=0;//maxx为所有字符串中剩余的长度最长的长度
    for(int i=0; i<n; i++)maxx=max(maxx,len[i]-pos[i]);
    if(x+maxx>dep)return ;//当前长度加上剩余最长长度的和大于预测长度则返回
    if(maxx==0){ans=x;return;}//如果剩余的长度都为零则搜索结束
    int book[N];
    for(int i=0; i<4; i++)//相当于四个方向,每一种情况都尝试一下
    {
        int flag=0;
        for(int j=0; j<n; j++)
            if(s[j][pos[j]]==to[i])book[j]=pos[j]+1,flag=1;
            else book[j]=pos[j];
        if(flag)dfs(x+1,book);
        if(ans)return ;
    }
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        ans=0,dep=0;
        for(int i=0; i<n; i++)
        {
            scanf("%s",s[i]);
            len[i]=strlen(s[i]);//记录每个字符串的长度
            dep=max(dep,len[i]);//找到最长的一个字符串的长度,设为初始深度
        }
        while(1)
        {
            mem(pos,0);//pos数组对应的是每个字符串匹配过的个数
            dfs(0,pos);
            if(ans)break;//所有的都可以匹配结束
            dep++;
        }
        printf("%d\n",ans);
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Informer: Beyond Efficient Transformer for Long Sequence Time-Series Forecasting是一篇2021年发表在AAAI会议上的论文,它提出了一种名为Informer的方法,用于解决长时间序列预测的问题。\[2\]这篇论文的目标是在长时间序列预测中提高预测能力并提高效率。传统的Transformer方法在长时间序列预测上存在一些局限性,而Informer通过引入一些新的机制来克服这些局限性。\[3\]具体来说,Informer采用了一种多层次的注意力机制,以便更好地捕捉长时间序列中的依赖关系,并引入了一种自适应长度的编码器和解码器,以提高对长序列的建模能力。通过这些改进,Informer在长时间序列预测任务上取得了更好的效果。 #### 引用[.reference_title] - *1* *3* [Informer: Beyond Efficient Transformer for Long SequenceTime-Series Forecasting](https://blog.csdn.net/lwera/article/details/127389652)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Informer:超越Transformer的长时间序列预测模型](https://blog.csdn.net/zuiyishihefang/article/details/123437169)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值