Solution

不由分说地枚举分割点

令 \(f[i][j]\) 表示原串处理到 \(i\) ,\(s_1\) 处理到 \(j\),\(s_2\) 最多能处理到哪里

采用主动转移

任意情况, \(f[i][j] \to f[i+1][j]\)

如果 \(s[i+1]=s_1[j+1]\) ,那么 \(f[i][j] \to f[i+1][j+1]\)

如果 \(s[i+1]=s_2[f[i][j]+1]\) ,那么 \(f[i][j]+1 \to f[i+1][j]\)

时间复杂度 \(O(n^3)\)

#include <bits/stdc++.h>
using namespace std; int n,m,l1,l2;
char s[405],t[405],*s1,*s2;
int f[405][405]; void sh(int x,int &y) {
y=max(x,y);
} signed main() {
ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--) {
cin>>s+1>>t+1;
n=strlen(s+1);
m=strlen(t+1);
int ans=0;
for(int d=0;d<=m;d++) {
s1=t;
s2=t+d;
l1=d;
l2=m-d;
memset(f,-0x3f,sizeof f);
f[0][0]=0;
{
int i=0,j=0;
sh(f[i][j],f[i+1][j]);
if(s[i+1]==s1[j+1]) sh(f[i][j],f[i+1][j+1]);
if(s[i+1]==s2[f[i][j]+1]) sh(f[i][j]+1,f[i+1][j]);
}
for(int i=1;i<=n;i++) {
for(int j=0;j<=min(l1,i);j++) {
sh(f[i][j],f[i+1][j]);
if(s[i+1]==s1[j+1]) sh(f[i][j],f[i+1][j+1]);
if(f[i][j]>=0 && s[i+1]==s2[f[i][j]+1]) sh(f[i][j]+1,f[i+1][j]);
}
}
if(f[n][l1]==l2) ans=1;
}
cout<<(ans>0?"YES":"NO")<<endl;
}
}

[CF1303E] Erase Subsequences - dp的更多相关文章

  1. Codeforces 1303E. Erase Subsequences 代码(dp 字符串压缩一维状态优化)

    https://codeforces.com/contest/1303/problem/E #include<bits/stdc++.h> using namespace std; ; i ...

  2. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences             ...

  4. HDU 2227 Find the nondecreasing subsequences(DP)

    Problem Description How many nondecreasing subsequences can you find in the sequence S = {s1, s2, s3 ...

  5. Distinct Subsequences (dp)

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  6. HDU 2227 Find the nondecreasing subsequences dp思想 + 树状数组

    http://acm.hdu.edu.cn/showproblem.php?pid=2227 用dp[i]表示以第i个数为结尾的nondecreasing串有多少个. 那么对于每个a[i] 要去找 & ...

  7. Codeforces1303E. Erase Subsequences

    转换一下题意,就相当于问t能不能和s中2个不相同的子串相同,我们可以将t串拆成2个子串t1,t2,得到状态dp[i][j][k]=0/1,表示s判断到i位,t1判断到j位,t2判断到k位,0/1表示是 ...

  8. 2021record

    2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...

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

随机推荐

  1. 20200105--python学习第七天

    今日内容 深浅拷贝 文件操作 内容回顾及补充 1.内容回顾 计算机基础 编码 语法 if/while/for 数据类型 type/id/range 运算符 2.面试题 a.公司线上的系统用的是什么? ...

  2. k8s 开船记-全站登船:Powered by .NET Core on Kubernetes

    今天 18:30 左右,我们迈出了 kubernetes 航行的关键一步——全站登船,完成了全站应用从 docker swarm 集群向 k8s 集群的切换,以前所未有的决心与信心重新开起这艘巨轮,而 ...

  3. chrome报错:您目前无法访问 因为此网站使用了 HSTS

    chrome报错:您目前无法访问 因为此网站使用了 HSTS 其然: 现象 :访问github仓库报错'您目前无法访问XXXX 因为此网站使用了 HSTS' 解决方法:清理HSTS的设定,重新获取.c ...

  4. React之props、state和render函数的关系

    1.当组件中的state或者props发生改变的的时候,render函数就会被重新执行 2.当父组件的render函数被运行时,它的子组件的render都将被重新运行一次 3.子组件作为父组件里的一个 ...

  5. 单页应用(SPA,Single-page-App)和多页应用(MPA,Multi-page App)的区别

    单页应用(SPA,Single-page-App)和多页应用(MPA,Multi-page App)的区别 参考博客:https://www.jianshu.com/p/4c9c29967dd6

  6. HTML连载70-相片墙、盒子阴影和文字阴影

    一. 制作一个相片墙 二. <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  7. Python入门1.0

    第一阶段 基础到高级 ATM+购物车项目 选课系统 计算机病毒 病毒程序(windows)防止被杀死 控制键盘摄像头 上传对方数据 有很强的伪装性 服务端(阿里云) 第二阶段 商业项目 博客系统 路飞 ...

  8. Orleans[NET Core 3.1] 学习笔记(四)( 3 )监控Orleans Silo的方式 OrleansDashboard

    简介 Orleans用起来的确很爽,更爽的是咱们有能监控它的工具. OrleansDashboard 这个工具是一个可视化的Silo监控工具,Silo和Grain的活跃状态一目了然,各个接口的响应速度 ...

  9. 使用placeholder属性设置input文本框的提示信息

    input文本框中设置提示信息,可以使用placeholder属性 <!DOCTYPE html> <html> <head> <meta charset=& ...

  10. myeclipse 2018 intaslled jars JREs 选项区别,及注意事项

    Standard 1.1.x VM与Standard VM的区别 在Eclipse或MyEclipse中要设置Installed JREs时,有三个选择: - Execution Environmen ...