题意:输入四个字符串a,b,w,z,经过一定的替换规则,问w或者w的子串中是否包含z.

替换规则如下.w中的字符a全部替换成a字符串,b字符全部替换成b字符串.

枚举过程,

根据替换规则对w进行替换,生成新的字符串w2,

对w2的子串中长度小于等于z的字符串全部枚举一遍,题目输入限制n<=16,那么,w的子串最多为2^16

#include <iostream>
#include<map>
#include<memory.h>
#include<stdio.h>
#include<string>
#include<queue>
#include<vector>
using namespace std;
string a;
string b;
string bg;
string ed;
map<string, int>maps;
queue<string>q;
int ok = ; void judge(string temp)
{
//枚举字串
for (int i = ;i < temp.size() - ;i++)
{
string temp2 = "";
for (int j = i;j < i + ed.size() && j < temp.size();j++)
{
temp2 += temp[j];
}
if (temp2 == ed)
{
ok = ;
return;
}
else if (maps[temp2] == )
{
q.push(temp2);
maps[temp2] = ;
}
}
} void bfs(string temp)
{ if (temp.size() >= ed.size())
judge(temp);
if (ok)
return;
q.push(temp);
maps[temp] = ;
while (q.empty() == false)
{
temp = q.front();
q.pop();
string temp2 = "";
for (int i = ;i < temp.size();i++)
{
if (temp[i] == 'a')
temp2 += a;
if (temp[i] == 'b')
temp2 += b;
}
judge(temp2);
if (ok)
return;
}
} int main()
{
while (cin >> a)
{
cin >> b >> bg >> ed;
ok = ;
maps.clear();
while (q.empty() == false)
q.pop();
bfs(bg);
if (ok)
cout << "YES" << endl;
else
cout << "NO" << endl; }
}

uva-310-L--system-暴力枚举的更多相关文章

  1. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  2. Uva 10167 - Birthday Cake 暴力枚举 随机

      Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys ...

  3. UVA 725 division【暴力枚举】

    [题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...

  4. UVa 10603 Fill [暴力枚举、路径搜索]

    10603 Fill There are three jugs with a volume of a, b and c liters. (a, b, and c are positive intege ...

  5. Gym 101194L / UVALive 7908 - World Cup - [三进制状压暴力枚举][2016 EC-Final Problem L]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

  6. UVA 10012 How Big Is It?(暴力枚举)

      How Big Is It?  Ian's going to California, and he has to pack his things, including his collection ...

  7. uva 11088 暴力枚举子集/状压dp

    https://vjudge.net/problem/UVA-11088 对于每一种子集的情况暴力枚举最后一个三人小组取最大的一种情况即可,我提前把三个人的子集情况给筛出来了. 即 f[S]=MAX{ ...

  8. UVA - 11464 Even Parity 【暴力枚举】

    题意 给出一个 01 二维方阵 可以将里面的 0 改成1 但是 不能够 将 1 改成 0 然后这个方阵 会对应另外一个 方阵 另外一个方阵当中的元素 为 上 下 左 右 四个元素(如果存在)的和 要求 ...

  9. 紫书 例题 10-2 UVa 12169 (暴力枚举)

    就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去 ...

  10. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

随机推荐

  1. python re 实例

    #!/usr/bin/env python#_*_coding:utf-8_*_ import reimport timeimport jsonimport MySQLdbimport context ...

  2. PHP_EOL DIRECTORY_SEPARATOR

    换行符 PHP_EOL unix系列用 \n windows系列用 \r\n mac用 \r PHP中可以用PHP_EOL来替代,以提高代码的源代码级可移植性 路径上的斜杠    DIRECTORY_ ...

  3. python中pip和pygame的安装

    1.安装pip和pygame都很简单.首先咱们来安装pip,官网https://pypi.python.org/pypi/pip#download,下载pip的压缩文件,并将其解压. 我们在cmd的p ...

  4. SpringMVC---400错误The request sent by the client was syntactically incorrect ()

    在SpringMVC中使用@RequestBody和@ModelAttribute注解时遇到了很多问题,现记录下来. @ModelAttribute这个注解主要是将客户端请求的参数绑定参数到一个对象上 ...

  5. hadoop-n.x.y-src.tar.gz 、hadoop-n.x.y-src.tar.gz.asc 、hadoop-n.x.y-src.tar.gz.md5 、hadoop-n.x.y-src.tar.gz.mds是什么?

    不多说,直接上干货! 我这里,以hadoop-2.6.0为例. hadoop-n.x.y.tar.gz.mds,此mds文件是为了检验在下载和移动文件过程中文件的完整性. 通过验证文件的md5值去检验 ...

  6. react中的数据请求

    在react中,没有提供专门的请求数据的模块,所以我们可以采用第三方请求数据的模块进行数据请求,常见的有axios和fetch-jsonp,下面来总结这两种方式的用法. axios 查看文档 http ...

  7. Java-Runoob-高级教程-实例-方法:02. Java 实例 – 输出数组元素

    ylbtech-Java-Runoob-高级教程-实例-方法:02. Java 实例 – 输出数组元素 1.返回顶部 1. Java 实例 - 输出数组元素  Java 实例 以下实例演示了如何通过重 ...

  8. 学习笔记之TensorFlow

    TensorFlow https://www.tensorflow.org/ An open source machine learning framework for everyone Tensor ...

  9. [UE4]工程设置:自动捕获鼠标、通过代码设置鼠标显示隐藏、输入模式、编译时自动保存

    一.在4.20版本中运行游戏,在没有进行任何设置的情况下,游戏不会自动捕获鼠标,游戏不会接受输入,需要手动点一下游戏界面才行.如果要跟老版本一样运行游戏自动捕获鼠标,需要进行设置 二.也可以通过代码的 ...

  10. golang 常量的用法

    1.Golang常量的用法 //常量的用法 var num int num =9 //1.常量声明的时候必须赋值 const tax int = 0 //2.常量值是无法修改的 //tax = 10 ...