题目传送门

 /*
题意:两块扑克牌按照顺序叠起来后,把下半部分给第一块,上半部给第二块,一直持续下去,直到叠成指定的样子
DFS:直接模拟搜索,用map记录该字符串是否被搜过。读懂题目是关键。
*/
/************************************************
Author :Running_Time
Created Time :2015-8-3 13:57:55
File Name :POJ_3087.cpp
*************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 5e3 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
map<string, int> cnt;
string str;
bool vis[MAXN][MAXN];
int res, ct;
int n; void DFS(string s, string t, int dep) {
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;
string tmp = "";
for (int i=; i<n; ++i) {
tmp += t[i]; tmp += s[i];
}
if (tmp == str) {
if (res > dep) res = dep;
return ;
}
s = ""; t = "";
for (int i=; i<n; ++i) s += tmp[i];
for (int i=n; i<*n; ++i) t += tmp[i];
DFS (s, t, dep + );
} int main(void) { //POJ 3087 Shuffle'm Up
int T, cas = ; scanf ("%d", &T);
while (T--) {
scanf ("%d", &n);
string s, t;
cin >> s >> t; cin >> str;
res = INF; ct = ; cnt.clear (); memset (vis, false, sizeof (vis));
DFS (s, t, );
printf ("%d %d\n", ++cas, res == INF ? - : res);
} return ;
}

DFS POJ 3087 Shuffle'm Up的更多相关文章

  1. POJ 3087 Shuffle'm Up(洗牌)

    POJ 3087 Shuffle'm Up(洗牌) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 A common pas ...

  2. POJ.3087 Shuffle'm Up (模拟)

    POJ.3087 Shuffle'm Up (模拟) 题意分析 给定两个长度为len的字符串s1和s2, 接着给出一个长度为len*2的字符串s12. 将字符串s1和s2通过一定的变换变成s12,找到 ...

  3. POJ 3087 Shuffle'm Up

    Shuffle'm Up Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  4. POJ 3087 Shuffle'm Up DFS

    link:http://poj.org/problem?id=3087 题意:给你两串字串(必定偶数长),按照扑克牌那样的洗法(每次从S2堆底中拿第一张,再从S1堆底拿一张放在上面),洗好后的一堆可以 ...

  5. POJ 3087 Shuffle'm Up 线性同余,暴力 难度:2

    http://poj.org/problem?id=3087 设:s1={A1,A2,A3,...Ac} s2={Ac+1,Ac+2,Ac+3,....A2c} 则 合在一起成为 Ac+1,A1,Ac ...

  6. poj 3087 Shuffle'm Up ( map 模拟 )

    题目:http://poj.org/problem?id=3087 题意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s ...

  7. POJ 3087 Shuffle'm Up bfs

    题目链接:Shuffle'm Up 除了英文题有点恶心.发现模拟 + bfs 就可以过的时候,就是水了. 一个bug 就是filp函数得到string s12失败了.恩.据大腿告知,string 并不 ...

  8. POJ 3087 Shuffle'm Up (模拟+map)

    题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...

  9. [暴力搜索] POJ 3087 Shuffle'm Up

    Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10003   Accepted: 4631 Des ...

随机推荐

  1. DEA中MAVEN项目有多个子目录,如何加载构建

    ddts这个项目有三个子目录,每个子目录下面也都有一个 pom.xml       此时需要 右键子目录的 pom.xml,选择Add as Maven Project,在上图中cli.core两个目 ...

  2. ssh远程登录

    ssh root@192.168.124.128 密钥登录: 1).ssh-keygen 生成公钥和私钥 [root@rhel5 ~]# ssh-keygen -t rsa Generating pu ...

  3. IntentService用于服务中开启子线程的自动关闭

    package com.pingyijinren.test; import android.app.IntentService; import android.content.Intent; impo ...

  4. jQuery插件之ajaxFileUpload(ajax文件上传)

    一.ajaxFileUpload是一个异步上传文件的jQuery插件. 传一个不知道什么版本的上来,以后不用到处找了. 语法:$.ajaxFileUpload([options]) options参数 ...

  5. [bzoj2882]工艺_后缀数组

    工艺 bzoj-2882 题目大意:题目链接. 注释:略. 想法: 跟bzoj1031差不多啊. 把串倍长后扫$sa$数组. 最后再统计答案即可. Code: #include <iostrea ...

  6. bzoj——3555: [Ctsc2014]企鹅QQ

    3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 2617  Solved: 921[Submit][Statu ...

  7. nginx: [emerg] unknown directive "聽" in D:\software03\GitSpace\cms\nginx-1.14.0/conf/nginx.conf:36

    nginx: [emerg] unknown directive "聽" in D:\software03\GitSpace\cms\nginx-1.14.0/conf/nginx ...

  8. 选择器的使用(target选择器)

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta ...

  9. hdu 4291 矩阵幂 循环节

    http://acm.hdu.edu.cn/showproblem.php?pid=4291 凡是取模的都有循环节-----常数有,矩阵也有,并且矩阵的更奇妙: g(g(g(n))) mod 109  ...

  10. kvc VS kvo

    Kvo是Cocoa的一个重要机制,它主要是用于对一个属性的新旧值的监控. 例如说依据A(数 据类)的某个属性值变化,B(view类)中的某个属性做出对应变化.对于MVC,kvo应用的地方很广泛. 使用 ...