Educational Codeforces Round 68 (Rated for Div. 2)-C-From S To T
You are given three strings ss, tt and pp consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.
During each operation you choose any character from pp, erase it from pp and insert it into string ss (you may insert this character anywhere you want: in the beginning of ss, in the end or between any two consecutive characters).
For example, if pp is aba, and ss is de, then the following outcomes are possible (the character we erase from pp and insert into ss is highlighted):
- aba →→ ba, de →→ ade;
- aba →→ ba, de →→ dae;
- aba →→ ba, de →→ dea;
- aba →→ aa, de →→ bde;
- aba →→ aa, de →→ dbe;
- aba →→ aa, de →→ deb;
- aba →→ ab, de →→ ade;
- aba →→ ab, de →→ dae;
- aba →→ ab, de →→ dea;
Your goal is to perform several (maybe zero) operations so that ss becomes equal to tt. Please determine whether it is possible.
Note that you have to answer qq independent queries.
The first line contains one integer qq (1≤q≤1001≤q≤100) — the number of queries. Each query is represented by three consecutive lines.
The first line of each query contains the string ss (1≤|s|≤1001≤|s|≤100) consisting of lowercase Latin letters.
The second line of each query contains the string tt (1≤|t|≤1001≤|t|≤100) consisting of lowercase Latin letters.
The third line of each query contains the string pp (1≤|p|≤1001≤|p|≤100) consisting of lowercase Latin letters.
For each query print YES if it is possible to make ss equal to tt, and NO otherwise.
You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
4
ab
acxb
cax
a
aaaa
aaabbcc
a
aaaa
aabbcc
ab
baaa
aaaaa
YES
YES
NO
NO
In the first test case there is the following sequence of operation:
- s=s= ab, t=t= acxb, p=p= cax;
- s=s= acb, t=t= acxb, p=p= ax;
- s=s= acxb, t=t= acxb, p=p= a.
In the second test case there is the following sequence of operation:
- s=s= a, t=t= aaaa, p=p= aaabbcc;
- s=s= aa, t=t= aaaa, p=p= aabbcc;
- s=s= aaa, t=t= aaaa, p=p= abbcc;
- s=s= aaaa, t=t= aaaa, p=p= bbcc.
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
const int maxn=1e5+;
typedef long long ll;
using namespace std;
string s,t,p;
int vis[maxn];
int dp[][];
string str;
int main()
{ int T;
cin>>T;
while(T--)
{
cin>>s>>t>>p;
str=s+p;
memset(vis,,sizeof(vis));
int len1=t.length();
int len2=str.length();
int len3=s.length();
int ans=;
memset(dp,,sizeof(dp));
for(int i=;i<=len1;i++)
{
for(int j=;j<=len3;j++)
{
if(t[i-]==s[j-])
{
dp[i][j]=max(dp[i][j],dp[i-][j-]+);
}
else
{
dp[i][j]=max(dp[i-][j],dp[i][j-]);
}
}
}
int flag=;
if(dp[len1][len3]==len3)
{
flag=;
}
if(flag==)
{
puts("NO");
continue;
}
else
{
for(int i=;i<len1;i++)
{
for(int j=;j<len2;j++)
{
if(str[j]==t[i]&&vis[j]==)
{
vis[j]=;
ans++;
break;
}
}
}
if(ans==len1)
{
puts("YES");
}
else
{
puts("NO");
}
} }
return ;
}
Educational Codeforces Round 68 (Rated for Div. 2)-C-From S To T的更多相关文章
- Educational Codeforces Round 68 (Rated for Div. 2)---B
http://codeforces.com/contest/1194/problem/B /* */ # include <bits/stdc++.h> using namespace s ...
- Educational Codeforces Round 68 (Rated for Div. 2)补题
A. Remove a Progression 签到题,易知删去的为奇数,剩下的是正偶数数列. #include<iostream> using namespace std; int T; ...
- Educational Codeforces Round 68 (Rated for Div. 2) C. From S To T (字符串处理)
C. From S To T time limit per test1 second memory limit per test256 megabytes inputstandard input ou ...
- Educational Codeforces Round 68 (Rated for Div. 2) D. 1-2-K Game (博弈, sg函数,规律)
D. 1-2-K Game time limit per test2 seconds memory limit per test256 megabytes inputstandard input ou ...
- Educational Codeforces Round 68 (Rated for Div. 2)D(SG函数打表,找规律)
#include<bits/stdc++.h>using namespace std;int sg[1007];int main(){ int t; cin>>t; while ...
- Educational Codeforces Round 68 (Rated for Div. 2)-D. 1-2-K Game
output standard output Alice and Bob play a game. There is a paper strip which is divided into n + 1 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
随机推荐
- PHP7 生产环境队列 Beanstalkd 正确使用姿势
应用场景 为什么要用呢,有什么好处?这应该放在最开头说,一件东西你只有了解它是干什么的,适合干什么,才能更好的与自己的项目相结合,用到哪里学到哪里,学了不用等于不会,我们平时就应该多考虑一些这样的问题 ...
- 比原链(Bytom)正式开源Bytom-JavaScript库
12月13日,比原链(Bytom)正式开源Bytom-JavaScript库,这个库是官方原生支持的新一代JavaScript SDK接口.JavaScript是世界上最多人使用的解释性脚本语言,JS ...
- Flutter 容器(7) - DecoratedBox
DecoratedBox: 装饰容器,在其子widget绘制前(或后)绘制一个装饰Decoration(如背景.边框.渐变等) import 'package:flutter/material.dar ...
- Linux内核之 内核同步
上文我们介绍过进程调度,Linux内核从2.6版本开始支持内核抢占,所以内核很多代码也需要同步保护. 一.同步介绍 1.临界区与竞争条件 所谓临界区(critical regions)就是访问和操作共 ...
- 实验室外的攻防战 UOJ#180 [树状数组]
实验室外的攻防战 UOJ#180 [树状数组] 题目 时针指向午夜十二点,约定的日子--2月28日终于到来了.随着一声枪响,伏特跳蚤国王率领着他的跳蚤大军们包围了 \(picks\) 博士所在的实验室 ...
- Linux top详解
命令 top 参数说明: d:改变显示的更新速度 q: 没有任何延迟的显示速度 c:切换显示模式,共有两种模式,一是只显示执行档的名称,零一种显示完整的路径与名称S:累计模式,会将已完成或消失的子行 ...
- 每天都在用String,你真的了解吗?
1.String概述 java.lang.String 类代表字符串.Java程序中所有的字符串文字(例如"abc")都可以被看作是实现此类的实例 String 中包括用于检查各个 ...
- nova 数据库中删除虚机
Database changed MariaDB [nova]> SET FOREIGN_KEY_CHECKS=; Query OK, rows affected (0.000 sec) Mar ...
- 计算机网络-网络层(6)ICMP协议
互联网控制报文协议(ICMP,Internet Control Message Protocol),被主机和路由器用来彼此沟通网络层的信息 ICMP报文是承载在IP分组中的,即lCMP报文是作为IP有 ...
- 第4篇scrum冲刺(5.24)
一.站立会议 1.照片 2.工作安排 成员 昨天已完成的工作 今天的工作安排 困难 陈芝敏 完成云开发配置,初始化数据库: 线下模块(还剩下获取词的数据库) 倒计时模块的初加载还是有点慢 冯晓凤 ...