Test instructions: Tell you two strings A and B, requires a stack operation to produce B string, the order of output operations, if there are multiple sets of output in dictionary order output.
Sample Input
Madam
Adamm
Long
Short
Sample Output
[
I i i o o o i o O
I i i o o o o i o
I i o i o i o i o O
I i o i o i o o i o
]
[
I i o i o i o O
]
DFS has been relatively weak, although the idea has, but always write bad
1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <queue>7#include <map>8#include <stack>9 using namespacestd;Ten #defineMOD 1000000007 One Const intinf=0x3f3f3f3f; A Const Doubleeps=1e-5; - #defineCL (a) memset (A,0,sizeof (a)) - #defineTS printf ("*****\n"); the Const intmaxn=1005; - intN,m,tt; -stack<int>s; - Chars1[ -],s2[ -]; + intLen1,len2; - intnum[ -]; + voidDfsintIintJintk) A { at if(j==len2) - { - for(intp=0;p <k;p++) - { - if(Num[p]) printf ("I"); - Elseprintf"o"); in } -printf"\ n"); to return; + } - if(i<len1) the { * S.push (S1[i]); $num[k]=1;Panax NotoginsengDFS (i+1, j,k+1); - S.pop (); the } + if(!s.empty () &&s.top () = =S2[j]) A { the Charmm=s.top (); + S.pop (); -num[k]=0; $DFS (i,j+1, K +1); $ S.push (mm); - } - } the intMain () - {Wuyi inti,j,k; the #ifndef Online_judge -Freopen ("1.in","R", stdin); Wu #endif - while(SCANF ("%s%s", s1,s2)! =EOF) About { $len1=strlen (S1); -Len2=strlen (S2); -printf"[\ n"); -Dfs0,0,0); Aprintf"]\n"); + } the}
HDU 1515 Dfs