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< ...
随机推荐
- fastjson JSON.toJavaObject() 实体类首字母大写属性无法解析问题
fastjson JSON.toJavaObject() 实体类首字母大写属性无法解析问题
- spring oauth2获取token时WARN:Could not decode JSON for additional information: BaseClientDetails解决办法
错误描述 简述:oauth_client_details表中additional_information字段默认为null,ClientDetails实体类中类型为Map<String,Obje ...
- 网络安全传输系统-sprint3账号管理子系统设计
part1:sqlite嵌入式数据库移植 1.数据库系统构成:访问数据库应用-->管理数据库系统-->数据库存储(自上而下) 2.数据库中数据以表的形式而存在.表与表之间可能存在关联关系( ...
- 【av68676164(p55-p58)】 Intel CPU和Linux内存管理
7.4.1 Intel CPU物理结构 https://www.cnblogs.com/megachen/p/9768115.html x86实模式 实模式 20位:1M内存空间 地址表示方式:段地址 ...
- 6、单例模式 Singleton模式 只有一个实例 创建型模式
1.了解Singleton模式 程序在运行时,通常都会生成很多实例.例如,表示字符串的java . lang . string类的实例与字符串是- -对- -的关系,所以当有1000个字符串的时候,会 ...
- SkyWalking 搭建及简单使用(Linux)
1.需求 公司项目采用微服务的架构,服务很多,人工监控是不可能的,项目的访问量很大,想通过日志查找某个方法中性能的问题也是非常困难的.但是系统的性能问题是不能忽视的.系统性能检测的问题如鲠在喉,经过长 ...
- 修改mac系统名字&&神秘bogon
问题分析 你是否遇见过突然终端突然出现奇怪 bogon # name @ bogon in ~ [22:31:01] $ 这是因为终端会先向 DNS 请求查询当前 IP 的反向域名解析的结果,如果查询 ...
- IE6和IE11之间 表单提交 按钮设置了disabled属性
JSP代码可以不看,就是一个表单,通过submit提交. <form action="mainAction.do?method=saveQuote" method=" ...
- Java 变量及运算符
Java概述 Java的发展可以归纳如下的几个阶段: (1)第一阶段(完善期):JDK 1.0 ( 1995年推出)一JDK 1.2 (1998年推出,Java更名为Java 2): (2)第二阶段( ...
- 定宽整形(C++11起)
定义于头文件 cstdint中int8_t.int16_t.int32_t.int64_t 分别为宽度恰为 8 . 16 . 32 和 64 位的有符号整数类型无填充位并对负值使用补码(仅若实现支持该 ...