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 ...
随机推荐
- github的版本控制master和branch develop
一.git版本控制原理 master(主分支), develop(分支),虽然是主分支和分支,却是平级关系,develop可以理解为开发库,master为生产库. 本地版本:master, devel ...
- PTA 1001 A+B Format
问题描述: Calculate a+b and output the sum in standard format -- that is, the digits must be separated i ...
- rtp传输h264
---恢复内容开始--- 基本概念的理解 H.264的主要目标:1.高的视频压缩比2.良好的网络亲和性 解决方案:VCL video coding layer 视频编码层NAL network abs ...
- AC自动机(模板+例题)
首先要明白AC自动机是干什么的: AC自动机其实就是一种多模匹配算法,那么你可能会问什么叫做多模匹配算法.下面是我对多模匹配的理解,与多模与之对于的是单模,单模就是给你一个单词,然后给你一个字符串,问 ...
- centos7中python2.7升级到python3.7
一.下载源码包 # 切换到root目录 [root@localhost ~] cd /root/ # 安装wget [root@localhost ~] yum -y install wget # 使 ...
- Java参数传递是值传递还是引用传递?
当一个对象被当作参数传递到一个方法后,在此方法内可以改变这个对象的属性,那么这里到底是值传递还是引用传递? 答:是值传递.Java 语言的参数传递只有值传递.当一个实例对象作为参数被传递到方法中时,参 ...
- fastadmin选择下拉框
fastadmin中要做下拉框的效果如下: 数据库中数据: 在对应model中添加一个方法: 控制器中添加一行: 在目录lang/zh-cn中找到你控制器名称所对应的文件添加配置: 在add.html ...
- Spring boot unable to determine jdbc url from datasouce
1. 首先删除 @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) 2. 在配置文件里添加完整的dataso ...
- sql 分组后查询出排序字段
select row_number() over(partition by CODE order by SEQUENCE) as RowIndex from Table 注:根据表的CODE 字 ...
- Selenium3+python自动化007-警告框
警告框 alert = driver.switch_to.alert alert.text() alert.accpet() alert.dismiss() # 导selenium包 from sel ...