[SCU 4501] DNA sequence (pressure DP)

Source: Internet
Author: User

SCU-4501

Given a number of DNA sequences, the shortest containing the length of all sequences
Contains not necessarily a continuous inclusion, it can not be a substring

Pressure DP
Construct each bit in turn
Mark the position of each string and press it into 6 binary numbers.
Then each state expands a string
And then expand all the other next one with the same string
Then drop the state into the queue and transfer it, and output the answer when each string goes to the end.
Can guarantee an answer of up to 40
Complexity of Time O(aNs?Le nn )

#pragma COMMENT (linker, "/stack:102400000,102400000")#include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <map>#include <set>#include <queue>using namespace STD;typedefpair<int,int> Pii;typedef Long LongLL;typedef unsigned Long LongULL;typedef DoubleDBL;typedef Long DoubleLdbl;#define MST (A, B) memset (A,b,sizeof (a) )#define CLR (a) MST (a,0)#define SQR (a) (a*a)structdata{intMask,res; DataintTmintTR): Mask (tm), res (TR) {}};intNCharinpt[Ten][Ten];inttlen[Ten];intbuff[Ten];intEncodeint*);int* Decode (int);BOOLCheckint*);intMain () {intTscanf("%d", &t); for(intck=1; ck<=t; ck++) {scanf("%d", &n); for(intI=0; i<n; i++) {scanf('%s ', Inpt[i]); tlen[i]=strlen(Inpt[i]); } queue<data>Que Set<int>Vis Que.push (Data (0,0)); while(Que.size ()) {Data &u=que.front ();int*used=decode (U.mask);if(check (used)) {printf("%d\n", u.res); Break;}BOOLban[Ten]={0}; for(intI=0; i<n; i++) {inttemp[Ten];if(used[i]>=tlen[i]| | Ban[i])Continue;CharNxt=inpt[i][used[i]]; for(intj=0; j<n; J + +) {Temp[j]=used[j];if(Temp[j]>=tlen[j])Continue;if(INPT[J][TEMP[J]]==NXT)                        {temp[j]++; ban[j]=1; }                }intNm=encode (temp);if(Vis.find (NM)!=vis.end ())Continue; Que.push (Data (nm, u.res+1));            Vis.insert (NM);        } que.pop (); } while(Que.size ()) Que.pop (); }return 0;}intEncodeintBuff[]) {intres=0; for(intj=m-1; i>=0; i--) res=res*6+buff[i];returnRes;}int* Decode (intNUM) { for(intI=0; i<n; i++) {buff[i]=num%6; Num/=6; }returnBuff;}BOOLCheckintCntc[]) { for(intI=0; i<n; i++)if(Cntc[i]<tlen[i])return 0;return 1;}

[SCU 4501] DNA sequence (pressure DP)

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.