HDU 1560 DNA Sequence A * difficulty: 1

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1560

Read the question carefully (!), you can find that the problem requires a shortest string, the string of discontinuous subsequence contains all the strings given by the topic

Because there are only 40 characters in total, try searching using a *

1. Store the state directly stored 40 characters, 4 of each character may not be sure.

Because it is required to include a discontinuous subsequence, just remember that the current string length is the length of each subsequence that is already contained in the current string.

For example, the input sample in the topic

4

ACGT

Atgc

Cgtts

Cagt

You can store a sequence like this

Atg:len=3,s[0]=1,s[1]=3,s[2]=0,s[3]=0,

Atc:len=3,s[0]=2,a[1]=2,s[2]=1,s[3]=1,

And because there are only 8 subsequence, each subsequence has a length of not more than 5, which means that the state array can be compressed in 6. Total no more than 6^9=10077696 states, space time to meet

2. Evaluation function randomly selected the longest length of the current not implemented, 2483MS clearance

#include <cstdio> #include <cstring> #include <algorithm> #include <queue>using namespace std; const int Maxsta=10077696;char str[8][6];int l[8];int grade[8][6];bool vis[maxsta];int s[8];int n;struct status{int le    N,f;    int STA; Status (): Len (0), F (0), STA (0) {} status (int _len,int _f,int _sta): Len (_len), F (_f), STA (_sta) {} bool operator &lt        ;(status s2) const {if (S2.len!=len) return len>s2.len;    Return f>s2.f;        } void Tos () {int tsta=sta;            for (int i=n-1;i>=0;i--) {s[i]=sta%6;        sta/=6;    } Sta=tsta;        } static int Tosta () {int sta=0;            for (int i=0;i<n;i++) {sta*=6;        Sta+=s[i];    } return STA;        } static int calcf (int sta) {int tmp[8];        int ans=0;            for (int i=n-1;i>=0;i--) {tmp[i]=sta%6;            sta/=6;        Ans=max (Ans,l[i]-tmp[i]);    } return ans; }};p Riority_queue<sTatus> que;int ed;int BFs () {while (!que.empty ()) Que.pop ();    Status St=status (0,STATUS::CALCF (0), 0);    Char ch[4]={' A ', ' G ', ' C ', ' T '};    Que.push (ST);    Vis[0]=true;        while (!que.empty ()) {status tp=que.top (); Que.pop ();        if (tp.sta==ed) return tp.len;            for (int i=0;i<4;i++) {tp.tos ();                for (int j=0;j<n;j++) {if (Ch[i]==str[j][s[j]]) {s[j]++;            }} int Tmpsta=status::tosta ();            if (Vis[tmpsta]) continue;            Vis[tmpsta]=true;            if (tmpsta==ed) return tp.len+1;        Que.push (Status (TP.LEN+1,STATUS::CALCF (Tmpsta), Tmpsta)); }} return-1;}    int main () {int T;    scanf ("%d", &t);        while (t--) {scanf ("%d", &n);        memset (vis,0,sizeof (VIS));            for (int i=0;i<n;i++) {scanf ("%s", Str[i]);            L[i]=strlen (Str[i]);        S[i]=l[i];        } ed=status::tosta ();     int Ans=bfs ();   printf ("%d\n", ans); } return 0;}

HDU 1560 DNA Sequence A * difficulty: 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.