题目链接

problem

给定一个01串s,定义rev(x)表示逐位翻转(0变1,1变0)x后并删去前导零后所得到的串。好的串定义如下:

s是好的串

如果x是好的串,则rev(x)也是好的串

如果a,b是好的串,则a+b(a,b按顺序拼接)也是好的串

你需要判断串t是否为好的

s,t保证不含前导零

solution

将s不断翻转,直到消失,中间过程中得到的串都是好的。这个比较显然。

然后将上面得到的某个串(假设为a)分别翻转(但是保留前导0)得到b,那么b也是好的。因为如果我们再拼接的时候想拼接上一个b串,那么就可以先在之前的串上加一个形如\(111000\)的串,然后rev一下,然后拼接上a,然后rev一下。这样就可以拼接上一个b串了。

具体实现,因为可以\(n^2\)dp。为了方便操作,可以先将s和t都反过来。这样所有的后缀就都变成了前缀。用\(f[i]\)表示前i个串是否可以拼接出来。如果\(f[i]\)可以拼接出来的话,那么就枚举一个\(j\in[1,n](n为s长度)\)。看\(t_i...t_{i+j}\)是否可以通过上述方式得到,并且更新f[i+j]的值即可。

code

/*
* @Author: wxyww
* @Date: 2019-12-21 08:07:44
* @Last Modified time: 2019-12-21 08:18:05
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
const int N = 1010;
ll read() {
ll x = 0,f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1; c = getchar();
}
while(c >= '0' && c <= '9') {
x = x * 10 + c - '0'; c = getchar();
}
return x * f;
}
char s[N],t[N];
int f[N];
int main() {
int T = read();
while(T--) {
scanf("%s",s + 1);
scanf("%s",t + 1);
int n = strlen(s + 1),m = strlen(t + 1);
memset(f,0,sizeof(f));
reverse(s + 1,s + n + 1);
reverse(t + 1,t + m + 1);
f[0] = 1; for(int i = 0;i < m;++i) {
if(!f[i]) continue;
int k = t[i + 1] ^ s[1];
for(int j = 1;j <= n && i + j <= m;++j) {
if((s[j] ^ t[i + j]) != k) break;
if(s[j] != s[j + 1]) f[i + j] = 1;
}
}
puts(f[m] ? "YES" : "NO"); } return 0;
}

nowcoder3274D binary的更多相关文章

  1. [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法

    二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...

  2. ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id

    出现场景:当点击"分类"再返回"首页"时,发生error退出   BUG描述:Caused by: java.lang.IllegalArgumentExcep ...

  3. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

  4. Leetcode 笔记 99 - Recover Binary Search Tree

    题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...

  5. Leetcode 笔记 98 - Validate Binary Search Tree

    题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...

  6. Leetcode: Convert sorted list to binary search tree (No. 109)

    Sept. 22, 2015 学一道算法题, 经常回顾一下. 第二次重温, 决定增加一些图片, 帮助自己记忆. 在网上找他人的资料, 不如自己动手. 把从底向上树的算法搞通俗一些. 先做一个例子: 9 ...

  7. Leetcode, construct binary tree from inorder and post order traversal

    Sept. 13, 2015 Spent more than a few hours to work on the leetcode problem, and my favorite blogs ab ...

  8. [LeetCode] Binary Watch 二进制表

    A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom ...

  9. [LeetCode] Find Leaves of Binary Tree 找二叉树的叶节点

    Given a binary tree, find all leaves and then remove those leaves. Then repeat the previous steps un ...

随机推荐

  1. MySQL5.7脚本自动安装

    脚本里面没有把同步时间写进去,这个写在最前面yum install -y ntp ntpdatecp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localti ...

  2. 检测值是否存在(??)(Freemarker的null值处理)

    使用形式: unsafe_expr?? 或 (unsafe_expr)?? 这个操作符告诉我们一个值是否存在.基于这种情况, 结果是 true 或 false. 访问非顶层变量的使用规则和默认值操作符 ...

  3. 小程序底部tapbar

    app.json "tabBar": { "color": "#ccc", "selectedColor": " ...

  4. Java题库——Chapter11 继承和多态

    1)Analyze the following code: public class Test { public static void main(String[ ] args) { B b = ne ...

  5. goweb- 对请求的处理

    对请求的处理 Go 语言的 net/http 包提供了一系列用于表示 HTTP 报文的结构,我们可以使用它 处理请求和发送相应,其中 Request 结构代表了客户端发送的请求报文,下面让我们看 一下 ...

  6. CSS 从大图中选取部分区域作为目标图标

    从大图中选取部分区域作为目标图标 by:授客 QQ:1033553122 1.图片素材 图片素材如下(大小:137px * 264px),图中从上到下,连续存放了两张100px * 100px的图   ...

  7. Cesium专栏-气象雷达动图(附源码下载)

    Cesium Cesium 是一款面向三维地球和地图的,世界级的JavaScript开源产品.它提供了基于JavaScript语言的开发包,方便用户快速搭建一款零插件的虚拟地球Web应用,并在性能,精 ...

  8. 关于discuz的fap.php 漏洞问题

    discuz后台SQL注入漏洞 discuz的/faq.php的$action == 'grouppermission'处理逻辑中,对$gids未进行初始化,黑客可通过构造特殊HTTP请求借助变量覆盖 ...

  9. [转载] Java 遍历 Map 的 5 种方式

    目录 1 通过 keySet() 或 values() 方法遍历 2 通过 keySet 的 get(key) 获取值 3 通过 entrySet 遍历 4 通过迭代器 Iterator 遍历 5 通 ...

  10. iTerm2 使用代理

    0x00 事件 因为 brew 安装极慢,所以需要 iTerm2 设置代理解决速度问题. 0x01 解决 代理软件开启本地 Http 端口: iTerm 设置代理: $ vim ~/.zshrc # ...