题目链接

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. vue项目在git commit时,使用eslint检测

    用vue-cli3创建新项目可以自定义配置,选择eslint,所以eslint不需要配置, 项目根目录下面生成一个 .eslintrc.js文件,里面可以自定义配置eslint规则 现在在开发的时候, ...

  2. vmware无法安装vmware authorization&windows无法启动VMware Authorization Service服务

    在vmware安装过程中或更新时,时常遇到vmware无法安装vmware authorization&windows无法启动VMware Authorization Service服务的情况 ...

  3. Django Forms ChoiceField 选项更新问题

    今天使用django的forms,发现单选后台新增数据后,前端表单选项不能刷新 class UserForm(forms.Form): name = forms.ChoiceField( choice ...

  4. ABP入门教程0 - 目录

    ABP入门教程 本教程主要讲解如何基于ABP实现CURD(增删改查)示例. 源码已分享:   GitHub   Gitee ABP入门教程0 - 目录 ABP入门教程1 - 开篇 ABP入门教程2 - ...

  5. PHP Loser 说说做前端需要如何进一步学习

    PHP Loser 说说做前端需要如何进一步学习 做前端的,需要如何进一步学习?书籍这个事情贵精不在多,我这里推荐两本即可: <javascript教程 高级程序设计> <CSS权威 ...

  6. 数组类的创建——DynamicArray.h

    完成DynamicArray类的具体实现 DynamicArray设计要点——类模板 动态确定内部数组空间的大小 实现函数返回数组长度 拷贝构造和赋值操作 DynamicArray类的声明 templ ...

  7. Zuul 修改 请求头、响应头 (死磕)

    疯狂创客圈 Java 高并发[ 亿级流量聊天室实战]实战系列 [博客园总入口 ] 架构师成长+面试必备之 高并发基础书籍 [Netty Zookeeper Redis 高并发实战 ] 前言 Crazy ...

  8. let definitions are not supported by current javascript

    修改为es6即可

  9. 微信公众号支付提示当前页面的URL未注册

    问题: 记一下前端时间自己做了一个微信公众号支付的功能,因为有一段时间没有接触过了微信支付方面的开发,居然忘记了在微信商户商户号中配置了对应的支付目录,所以提示我当前的域名是没有注册的. 设置支付目录 ...

  10. RandomAccessFile()实现用户注册功能, 新增,查询,更新

    package seday03.raf;import java.io.IOException;import java.io.RandomAccessFile;import java.util.Arra ...