Educational Codeforces Round 82 (Rated for Div. 2)E(DP,序列自动机)
#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,序列自动机)的更多相关文章
- Educational Codeforces Round 82 (Rated for Div. 2)
题外话 开始没看懂D题意跳了,发现F题难写又跳回来了.. 语文好差,码力好差 A 判第一个\(1\)跟最后一个\(1\)中\(0\)的个数即可 B 乘乘除除就完事了 C 用并查集判一下联通,每个联通块 ...
- 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 ...
- Educational Codeforces Round 82 (Rated for Div. 2)D(模拟)
从低位到高位枚举,当前位没有就去高位找到有的将其一步步拆分,当前位多余的合并到更高一位 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h&g ...
- [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 ...
- 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\),可加 ...
- Educational Codeforces Round 63 (Rated for Div. 2) D dp(最大连续子序列)
https://codeforces.com/contest/1155/problem/D 题意 一个n个数的数组\(a[i]\),可以选择连续的一段乘x,求最大连续子序列的值 题解 错误思路:贪心, ...
- Educational Codeforces Round 57 (Rated for Div. 2) D dp
https://codeforces.com/contest/1096/problem/D 题意 给一个串s,删掉一个字符的代价为a[i],问使得s的子串不含"hard"的最小代价 ...
- Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)
题:https://codeforces.com/contest/1257/problem/E 题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序 ...
- 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 ...
随机推荐
- ubuntu set up 5 - VIM
Edit ~/.vimrc source vimrc: :so ~/.vimrc 1. ctrl - left/right 切换tabs https://vim.fandom.com/wiki/Usi ...
- 【大道至简】NetCore3.1快速开发框架一:集成Swagger
在上一章节中,我们创建了基本的框架结构:https://www.cnblogs.com/fuyu-blog/p/12217647.html 下面我们测试接口和集成Swagger接口文档 一.接口测试 ...
- centos8 ftp
安装 yum install -y vsftpd 启动 systemctl start vsftpd.service 开机启动 systemctl enable vsftpd.service 查看状态 ...
- MapReduce第一个项目 WordCount
参考自林子雨大数据教学: http://dblab.xmu.edu.cn/blog/hadoop-build-project-using-eclipse/ 创建一个文件夹:放入一个文本文件:填 ...
- 左边div固定宽度,右边div自适应撑满剩下的宽度--实现方法汇总
神奇的事 其实有的方法(float.position.margin.flex)是有border像素的差 代码如下: <!DOCTYPE html><html><head ...
- Selenium3+python自动化007-Selenium常用定位方法
自动化测试只要掌握四步操作:获取元素,操作元素,获取返回结果,断言(返回结果与期望结果是否一致),最后自动出测试报告.元素定位在这四个环节中是至关重要的,如果说按学习精力分配的话,元素定位占70%:操 ...
- Python标准库之时间模块time与datatime模块详解
时间模块time与datatime 时间表示方式: 时间戳 格式化时间字符串 元组 时间戳格式: time.time()#输出1581664531.749063 元组格式: time.localtim ...
- Mybatis之连接池
一,前言 连接池有很多种,最为熟悉的比如c3p0,DBCP,druid等. mybatis支持三种内置的数据源类型: Pooled:实现dataSource接口,并且使用了池的思想. UNPo ...
- Tomcat的使⽤
准备 1.官⽹地址:http://tomcat.apache.org下载. 2.解压文件,并放到指定路径,给该文件授权. chmod -R 755 3.启动和停止 进入到/Users/lucas/Do ...
- Electron – 基础学习(1): 环境安装、创建项目及入门
这几天到年底了,公司也没啥事,闲着就到处瞅瞅.记得上一家公司的时候用 Electron+ng1 写过项目,只是那个时候项目框架都是别人搭的,自己只负责写功能,对Electron没啥认识. 这几天想着反 ...