#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
char s[],t[];
int n,m;
int nex[][];//nex[i][j]表示i位置以字母j+'a'最先出现的位置
int dp[][];//把t分割为t1和t2,dp[i][j]表示t1长度为i,t2长度为j时,在字符串s中的最小位置
int check(int x){
int y=m-x;
dp[][]=;
for(int i=;i<=x;++i)
for(int j=;j<=y;++j){
if(i==&&j==)
continue;
dp[i][j]=+n;
if(i&&dp[i-][j]<n)//如果t1长度为i-1,t2长度为j,此时s还没有到达n,可以在当前情况让t1向后添加一个字母,更新dp[i][j]为添加后的答案与原本答案取最小值
dp[i][j]=min(dp[i][j],nex[dp[i-][j]][t[i]-'a']);
if(j&&dp[i][j-]<n)//如果t2长度为j-1,t1长度为i,此时s还没有达到n,可以在当前情况让t2向后添加一个字母,更新dp[i][j]为添加后的答案与原本答案取最小值,两次取最小值后得到dp[i][j]的最优情况(从dp[i-1][j]推化而来还是从cp[i][j-1]推化而来)
dp[i][j]=min(dp[i][j],nex[dp[i][j-]][t[x+j]-'a']);
}
return dp[x][y]<=n;//如果t字符串能被分割为长度为x和y的两个字符串并且在s中长度不超过n那么就可以如此分割
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin>>T;
while(T--){
cin>>s+>>t+;
n=strlen(s+);
m=strlen(t+);
for(int i=;i<;++i)
nex[n][i]=+n;
for(int i=n;i;--i){
for(int j=;j<;++j)
nex[i-][j]=nex[i][j];
nex[i-][s[i]-'a']=i;
}
int flag=;
for(int i=;i<=m;++i)
if(check(i)){
cout<<"YES\n";
flag=;
break;
}
if(!flag)
cout<<"NO\n";
}
return ;
}

Educational Codeforces Round 82 (Rated for Div. 2)E(DP,序列自动机)的更多相关文章

  1. Educational Codeforces Round 82 (Rated for Div. 2)

    题外话 开始没看懂D题意跳了,发现F题难写又跳回来了.. 语文好差,码力好差 A 判第一个\(1\)跟最后一个\(1\)中\(0\)的个数即可 B 乘乘除除就完事了 C 用并查集判一下联通,每个联通块 ...

  2. Educational Codeforces Round 82 (Rated for Div. 2) A-E代码(暂无记录题解)

    A. Erasing Zeroes (模拟) #include<bits/stdc++.h> using namespace std; typedef long long ll; ; in ...

  3. Educational Codeforces Round 82 (Rated for Div. 2)D(模拟)

    从低位到高位枚举,当前位没有就去高位找到有的将其一步步拆分,当前位多余的合并到更高一位 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h&g ...

  4. [CF百场计划]#3 Educational Codeforces Round 82 (Rated for Div. 2)

    A. Erasing Zeroes Description You are given a string \(s\). Each character is either 0 or 1. You wan ...

  5. Educational Codeforces Round 58 (Rated for Div. 2) F dp + 优化(新坑) + 离线处理

    https://codeforces.com/contest/1101/problem/F 题意 有n个城市,m辆卡车,每辆卡车有起点\(s_i\),终点\(f_i\),每公里油耗\(c_i\),可加 ...

  6. Educational Codeforces Round 63 (Rated for Div. 2) D dp(最大连续子序列)

    https://codeforces.com/contest/1155/problem/D 题意 一个n个数的数组\(a[i]\),可以选择连续的一段乘x,求最大连续子序列的值 题解 错误思路:贪心, ...

  7. Educational Codeforces Round 57 (Rated for Div. 2) D dp

    https://codeforces.com/contest/1096/problem/D 题意 给一个串s,删掉一个字符的代价为a[i],问使得s的子串不含"hard"的最小代价 ...

  8. Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)

    题:https://codeforces.com/contest/1257/problem/E 题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序 ...

  9. 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 ...

随机推荐

  1. HTML/JavaScript实现地图以鼠标为圆心缩放和移动

    代码如下 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  2. redis 安装 集群 主从 哨兵 docker

    安装redis 官方文档 docker run -d --net host -v /opt/myconfig/redis/redis.conf:/usr/local/etc/redis/redis.c ...

  3. C#依赖注入 简体demo

      class Program { static void Main(string[] args) { Dal dal = new MySql(); dal.Add(); Dal dal1 = new ...

  4. unity一些操作汇总

    设置父物体高度自适应子物体:父物体添加ContentSizeFitter,设置Horizeontal Fit和Vertical Fit为Preferred Size. ScrollView设置Cone ...

  5. Selenium3+python自动化012-测试用例模块化

    测试用例模块化特点:为po模型做准备. 1.提取公共方法. 2.提取数据. 3.提取逻辑. # @Author:lsj # @version V1.0 # -*- coding:UTF-8 -*- i ...

  6. 我的翻译--GSMem:通过GSM频率从被物理隔离的计算机上窃取数据

    抽象概念 AG网络是指在物理上与公共互联网断开的网络.虽然近几年人们验证了入侵这类网络系统的可行性,但是从这种网络上获取数据仍然是一个有挑战的任务.在本文中,我们介绍GSMem,它是一个可以在蜂窝数据 ...

  7. 项目转移时发生的错误<springboot+mybatis(xml逆向工程自动生成)>

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'app ...

  8. SpringBoot整合WEB开发--(七)注册拦截器

    1.创建一个拦截器类实现HandlerInterceptor接口,重写其中的3个方法,这拦截器中方法的执行顺序为:preHandle--Controller--postHandle--afterCom ...

  9. svg 放大缩小后的比例

    function getCoords(evt) { // 计算出当前屏幕与svg的比例    var canvas = document.getElementById("canvase&qu ...

  10. Java注释&标识符

    注释: 单行注释:// 多行注释:/*   */ 文档注释:/**  */ 其中文档注释可以Export导出dox文档,常用Javadox标记如下: @author:指定Java程序的作者 @vers ...