DFS POJ 3087 Shuffle ' m up

Source: Internet
Author: User

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

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.