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)