Record the possible segmentation after the first I put, and then can be introduced into the division of the first i+1.
#include <cstdio>#include<cstring>#include<cmath>#include<queue>#include<map>#include<algorithm>using namespacestd;Const intmaxn= -;CharS1[MAXN],S2[MAXN],S[MAXN];structx{intb; X (intAintb) {A=A; B=b; }};intMain () {intT scanf"%d",&T); for(intCase=1; case<=t; case++) {memset (S1,0,sizeofS1); memset (S2,0,sizeofS2); memset (s),0,sizeofs); scanf ("%s%s%s", s1,s2,s); Queue<x>q[2];intnow=0; Map<int,BOOL>m; intLena=strlen (S1), Lenb=strlen (S2), lens=strlen (s); m[0]=1; Q[now].push (X (0,0)); for(intI=0; s[i];i++) {m.clear (); now=now^1; while(! q[now^1].empty ()) {X Head=q[now^1].front (); q[now^1].pop (); if(S1[head. A]==s[i]&&head. B+lens-i>=lenb&&m[head. A +1]==0) {Q[now].push (X (head). A+1, head. B)); M[head. A+1]=1; } if(S2[head. B]==s[i]&&head. A+lens-i>=lena&&m[head. a]==0) {Q[now].push (X (head). A,head. B+1)); M[head. A]=1; } } } intans=0; while(!Q[now].empty ()) {X Head=Q[now].front (); Q[now].pop (); if(head. A==lena&&head. B==LENB) ans=1; } printf ("Data Set%d:", case); if(ans==1) printf ("yes\n"); Elseprintf"no\n"); } return 0;}
HDU 1501 Zipper