DNA sequence HDU - 1560 (IDA*)

说说PSTN、ISDN、 ADSL三种互联网接入方式的区别。 互联网的接入方式: 电话拨号接入(PSTN) ISDN接入 ADSL接入 Cable MODEM接入 局域网接入 光纤接入(FDDI) 卫星接入 DDN专线 目前来说,ADSL和Cable MODEM比较常用,今天我们就先来说说PSTN、ISDN和ADSL的区别。 电话拨号接入(PSTN/POTS,Public Switched Telephone Network / Public Oold Telephone Service) 数据终端设备(DTE)通过数据通信设备(DCE)再连 阅读详情

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个DNA序列,要求出一个包含这n个序列的最短序列是多长

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,deep;
char c[10] = "ACGT";
struct node{
    char s[10];
    int len;
}a[10];
int pos[10];//记录第i个序列正在使用第几个位置
//具体来说也就是对第i的字符串比如ACGT,pos[i]=2代表前两个字符AC已经匹配好了,下次匹配要看第三个字符了
//其实它也代表了每个串已经匹配了的长度
int get_h(){
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans = max(ans,a[i].len-pos[i]);//找出当前情况下最长的未被匹配的长度为估测长度
    }
    return ans;
}
int dfs(int step){
    if(step + get_h() > deep)//当前长度+估测长度比deep还大的话就没有继续往下搜索的必要了
        return 0;
    if(!get_h())
        return 1;
    int temp[10];
    for(int i = 0; i < 4; i++){
        int flag = 0;
        for(int j = 1; j <= n; j++){
            temp[j] = pos[j];//先将pos保存起来
        }
        for(int j = 1; j <= n; j++){
            if(a[j].s[pos[j]] == c[i]){//如果这个串的这个位置匹配上了c[i]字符,那么说明可以指向下一位字符了,下次匹配这个字符串的时候看它的下一位字符了
                flag = 1;
                pos[j]++;
            }
        }
        if(flag){//这个字符串有符合的字符,就继续往下搜,尽量是一个字符串全匹配完
           if(dfs(step+1))
              return 1;
           for(int j = 1; j <= n; j++){//回溯还原pos
              pos[j] = temp[j];
           }

        }
    }
    return 0;
}
int main(){
    int t,maxn;
    cin >> t;
    while(t--){
        cin >> n;
        maxn = 0;
        for(int i = 1; i <= n; i++){
            cin >> a[i].s;
            a[i].len = strlen(a[i].s);
            maxn = max(maxn,a[i].len);
            pos[i] = 0;
        }
        deep = maxn;
        while(1){
            if(dfs(0)) break;
            deep++;
        }
        cout << deep << endl;
    }
    return 0;
}

模拟一下样例的话就是

红色即代表pos数组代表的位置 

  初始        1            2             3            4              5             6              7              8

ACGT     ACGT      ACGT      ACGT      ACGT      ACGT       ACGT       ACGT      ACGT 

ATGC     ATGC      ATGC      ATGC      ATGC      ATGC       ATGC       ATGC      ATGC 

CGTT     CGTT       CGTT      CGTT       CGTT      CGTT        CGTT       CGTT       CGTT 

CAGT     CAGT      CAGT      CAGT      CAGT      CAGT       CAGT       CAGT       CAGT  

1:ans:A

2:ans:AC

3:ans:ACA

4:ans:ACAG

5:ans:ACAGT

6:ans:ACAGTG

7:ans:ACAGTGC

8:ans:ACAGTGCT

长度为8

20、自定义用户窗体:从创建到使用 本文详细介绍了在Excel VBA中创建和使用自定义用户窗体的完整过程,涵盖从窗体设计、控件添加与属性设置,到事件处理程序编写及宏调用的各个环节。通过实际示例讲解了如何实现文本大小写转换和员工信息录入等功能,并深入解析了常用控件的属性与事件机制。同时提供了控件命名规范、快捷键使用、布局技巧等实用建议,帮助读者构建高效、交互性强的VBA用户界面。 阅读详情

相关推荐

linux下autocad完美替代品bricscad的安装运行

前言 在Linux平台下,能完美兼容.dwg文件的软件并不多。 虽然国产的中望和浩辰为适配uos操作系统,近期都推出了linux版本,但目前好像还没有对应的破姐流出。(如果有的话请私信我或留下评论) 然而有了这一款源自比利时的软件——bricscad,linux下查看和编辑.dwg文件再也不是噩梦了! 安装pj 资源链接:https://pan.baidu.com/s/1dC7zarlqwuO5fa4CBL_KGQ 提取码:24j6 1.下载对应的压缩包,解压并安装其中对应的deb或rpm软件包。 2.在C

weixin_35259117的博客 4478

C1. Increasing Subsequence (easy version)

put contains one integer n (1≤n≤2⋅105) — the number of elements in a. The second line of the input contains n integers a1,a2,…,an (1≤ai≤n), where ai is the i-th element of a. All these integers are pa...

轻舟载君不载愁 514

IB网络下不同租户业务隔离方案

IB(InfiniBand)网络隔离可以在不同的通信模式下实现,其中包括 IPoIB(IP over InfiniBand)通信模式。在 IPoIB 模式下,InfiniBand 网络可以承载 IP 数据包,使得基于 IP 的应用程序能够在 InfiniBand 网络上进行通信。在这种情况下,IB 网络隔离通常指通过配置 Partition Key(PKey)来实现不同的租户或应用程序之间的网络隔离。然而,IB 网络隔离并不仅限于 IPoIB 模式。

guganly的专栏 1527

HDU - 1560: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(cytosi...

橘嘉禾 364

SOLIDWORKS无法获得下列许可 无效的使用许可号码(-8,544,0) 解决办法大全

SOLIDWORKS无法获得下列许可 无效的使用许可号码(-8,544,0) 解决办法大全。版本:SolidWorks2021。电脑:惠普战66四代。软件安装不困难!

qq_43596278的博客 11万+

基于图神经网络的社交网络虚假账号检测系统 (Graph-based Fake Account Detection System, GFADS)

FOLLOWSRETWEETSSHAREDCOMMENTSLIKESMENTIONSUseruser_idusernamejoin_datebioavatar_urllocationverifiedis_fakeLOAD CSV这是决定模型性能的关键环节,需结合和。XXedge_indexy新账号缺乏历史数据和丰富关系。全网图可能包含数亿节点和数十亿边,难以直接训练。社交网络是动态变化的,虚假账号策略也在不断进化。获取大规模、高质量的真实/虚假账号标注数据非常困难。

Deng945201314的博客 1480

DNA sequence(深度搜索+剪枝)

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 DN

weixin_46657636的博客 467

分支界定法(branch and bound)与背包问题的代码实现

分支界定法(branch and bound)与背包问题的代码实现 LastEditTime: - 2021.2.3 不卖茶的吴龙茗茶 分支界定法是一种在整数规划中常用的算法,其主要思想为将大问题分割成小问题进行求解。分支界定法是围绕着一个二叉树进行的,以背包问题为例: 假设小明有一个背包,其总的容积为30,小明有三件东西可以带,三件东西的体积分别为:10,15,20。求问小明如何能够在背包中装下更大体积的物品? .

小吴同学的小屋 1882

HDU 1560 迭代加深 解题报告

hdu1560

onepointo 524

SMETANA 安装使用教程

关于SMETANA的安装和简单使用信息

qq_44940977的博客 1166

RH850系列芯片深度剖析 1.5-链接(ld)文件解析

基础编译过程分为四个阶段:预处理(Preprocessing)、编译(Compilation)、汇编(Assembly)、链接(Linking)。执行这四个阶段的程序(预处理器、编译器、汇编器、和链接器)一起构成了编译系统。CONSTANTS接下来的内存空间定义部分会使用这些常量来定义内存空间的范围,理论上来说不定义常量也没有影响,直接用魔鬼数字代替,定义常量的主要目的就是方便理解以及方便修改;从示例中可以看出,常量的值可以为16进制或者10十进制,而且10进制支持数量级单位(k级,M级);

本博客专注于嵌入式软件领域技术分享。 1427

DNA sequence HDU - 1560

DNA sequence HDU - 1560

weixin_29216119的博客 276

中国各城市土地利用类型(城市功能)数据集(shp)

中国各城市土地利用类型(城市功能)数据集时间:2018年全国范围的城市用地类型数据(居住/商业/交通用地等共计11类)分类:居住用地、商业用地、工业用地、医疗设施用地、体育文化设施用地、交通场站用地、绿地等用地类型含城市编码、一级分类5个、二级分类11个1、上海市。

你好,我是小张同学! 1335

hdu 1560 DNA sequence (IDA*)

DNA sequence Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 721    Accepted Submission(s): 349 Problem Description The twenty-fir

To be what you what to be! 1150

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

HDU 1560 DNA sequence (IDA*)

DNA sequence Time Limit: 15000/5000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5220Accepted Submission(s): 2447 Problem Description The twenty-first cent...

YIU 334

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

HDU-1560 DNA sequence(IDA*)

数据不是很大,AC后又进入前25了。 开始TLE 5次,一直以为是自己的估价函数没写好,不停的改成现在这个样子,结果还是TLE,百度到大神的代码后发现他的优化比我还少,就想到了一定是初始化的问题,改过之后立刻AC,debug真是一个艰辛的过程。 经过测试后,发现如果只有以DNA最大剩余长度为估价函数返回值,几乎要TLE,所以主要起作用的是剩余DNA中ACGT分别出现的次数的最大值的和

idealism_xxm的专栏 739

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

HDU 1560 DNA sequence(初学IDA*)

题面 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...

Yi_Qing_Z的博客 210

DNA sequence(HDU - 1560)(IDA*)

DNA sequence 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(guanin...

K_Code_的博客 373

hdu 1560 DNA sequence(IDA*)

DNA sequence Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3872    Accepted Submission(s): 1870   Problem Description The twenty-first ce...

albertluf的博客 274

HDU1560:DNA sequence(IDA*)

求一DNA串包含所有给定字串。ida*剪枝,预测函数为个匹配串为匹配部分最大长度。 代码: #include #include #include #include #include #include #include #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rev(i,a,b) for(int i=(a);i>=(b);i--)

一点一滴,从不止步! 607

HDU1560 DNA sequence (IDA*)

题目大意:给你n(n 思路:搜索。很容易看出来最少步数大于等于最长的字符长度,因此估值函数h() =  同一字符串中所有剩余没匹配字母长度的最大值 #include #include #define Max(a,b) a>b?a:b using namespace std; int n; struct T { char s[10]; int len; }a[10]; int

ACMer_quack&cheer 473

HDU1560 DNA sequence(IDA*)题解

DNA sequenceTime Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3503    Accepted Submission(s): 1681Problem DescriptionThe twenty-first century is ...

努力,奋斗 335

DNA sequence HDU - 1560(IDA*)

题目链接 题意: 题目分析: 首先注意到n的范围很小,可以得知答案序列并不会很长,直接深搜我们需要记录每一个序列正在匹配的位置,可以使用IDA* 来优化,启发函数就是当前未匹配的序列中的最大长度,这里我们假设其它未匹配序列都是最大长度的序列的子序列,故能验证启发函数的正确性 代码 #include <bits/stdc++.h> #define x first #define y second #define fi first #define se second #define pb push

m0_52007929的博客 169

hdu 1560 DNA sequence(IDA*)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1560 DNA sequence Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1505 Accepted Submission(s): 730 Problem Description The twenty-first century i

若忆_star 1150

HDU 1560 DNA sequence(IDA*)

DNA sequence Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2666    Accepted Submission(s): 1299 Problem Description The twenty-f

yasolx的博客 502

HDU 1560 DNA sequence(IDA*)

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(thy

SSimpLe_Y的博客 838
上一篇: Doing Homework hdu1074(状压dp)
下一篇: Students in Railway Carriage (思维)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值