Topic Portal
1 /*2 Test Instructions: The two cards are stacked in order, the lower half to the first, the upper half to the second, and continues until it is folded into the specified shape.3 DFS: Directly simulates the search, using map to record whether the string has been searched. Reading the topic is the key. 4 */5 /************************************************6 Author:running_time7 Created time:2015-8-3 13:57:558 File Name:P oj_3087.cpp9 *************************************************/Ten One#include <cstdio> A#include <algorithm> -#include <iostream> -#include <sstream> the#include <cstring> -#include <cmath> -#include <string> -#include <vector> +#include <queue> -#include <deque> +#include <stack> A#include <list> at#include <map> -#include <Set> -#include <bitset> -#include <cstdlib> -#include <ctime> - using namespacestd; in - #defineLson L, Mid, RT << 1 to #defineRson mid + 1, R, RT << 1 | 1 +typedefLong Longll; - Const intMAXN = 5e3 +Ten; the Const intINF =0x3f3f3f3f; * Const intMOD = 1e9 +7; $map<string,int>CNT;Panax Notoginseng stringstr; - BOOLVIS[MAXN][MAXN]; the intRes, CT; + intN; A the voidDFS (stringSstringTintDEP) { + if(!cnt.count (s)) cnt[s] = + +CT; - if(!cnt.count (t)) cnt[t] = + +CT; $ if(Vis[cnt[s]][cnt[t]])return ; $Vis[cnt[s]][cnt[t]] =true; - stringTMP =""; - for(intI=0; i<n; ++i) { theTMP + = T[i]; TMP + =S[i]; - }Wuyi if(TMP = =str) { the if(Res > DEP) res =DEP; - return ; Wu } -s =""; t =""; About for(intI=0; i<n; ++i) S + =Tmp[i]; $ for(intI=n; i<2*n; ++i) T + =Tmp[i]; -DFS (S, T, DEP +1); - } - A intMainvoid) {//POJ 3087 Shuffle ' m up + intT, CAS =0; scanf ("%d", &T); the while(t--) { -scanf ("%d", &n); $ strings, t; theCIN >> s >> t; CIN >>str; theres = INF; CT =0; Cnt.clear (); memset (Vis,false,sizeof(Vis)); theDFS (S, T,1); theprintf ("%d%d\n", ++cas, res = = INF? -1: res); - } in the return 0; the}
DFS POJ 3087 Shuffle ' m up