HDU1560 DNA sequence 迭代深搜IDA*

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1560
题意是给你一些DNA串,要你输出一串字符串使得它能包含所有的DNA串的序列,要求其字典序最小,长度最短。
代码:

#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define scanfprint() freopen("input.txt","r",stdin)
#define printfprint() freopen("output.txt","w",stdout)
#define mem(a,b) memset(a,b,sizeof(a))
const int spot=1000+10;
const int edge=100000+10;
const int maxn=10;
const double pi=acos(-1.0);
const int mod=1e9+7;
const double ips=0.000001;
int n,m,a[maxn],len[maxn],have[maxn],maxlen=0;
char s[maxn][maxn],ss[maxn]="ACGT";
bool flag=0;
int f()
{
    int ans=0,i;
    for(i=1; i<=n; i++)
        ans=max(ans,len[i]-have[i]);
    return ans;
}
void dfs(int maxlen)
{
    int i,j;
    int h=f();
    if(!h)
    {
        flag=1;
        return;
    }
    if(h>maxlen)
        return ;
    bool ok=0;
    int temp[maxn];
    memcpy(temp,have,sizeof(temp));
    for(i=1; i<=4; i++)
    {
        for(j=1; j<=n; j++)
            if(s[j][have[j]]==ss[i-1])
                ok=1,have[j]++;
        if(ok)
        {
            dfs(maxlen-1);
            if(flag)
                return ;
        }
        memcpy(have,temp,sizeof(have));
    }
}
int main()
{
    int nn,i,j;
    scanf("%d",&nn);
    while(nn--)
    {
        maxlen=0;
        flag=0;
        scanf("%d",&n);
        for(i=1; i<=n; i++)
        {
            scanf("%s",s[i]);
            len[i]=strlen(s[i]);
            have[i]=0;
            maxlen=max(maxlen,len[i]);
        }
        for(;;)
        {
            dfs(maxlen);
            if(flag)
                break;
            else
                maxlen++;
        }
        printf("%d\n",maxlen);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值