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. Python - 文件读取read()、readline()、readlines()区别

    前言 读取文件的三个方法:read().readline().readlines().均可接受一个方法参数用以限制每次读取的数据量,但通常不使用 read() 优点:读取整个文件,将文件内容放到一个字 ...

  2. 安装python3.7

    首先安装依赖包,centos里面是-devel,如果在ubuntu下安装则要改成-dev,依赖包缺一不可,一步一步复制到终端执行就可以! sudo yum -y groupinstall " ...

  3. Nginx是什么 ? 能干嘛 ?

    学习博客:https://blog.csdn.net/forezp/article/details/87887507 学习博客:https://blog.csdn.net/qq_29677867/ar ...

  4. linux学习--1. 文件系统

    文件目录结构 闲话篇: linux我也是最近才开始学,写随笔是为分享学习经验的同时也留着供自己以后来参考.因为linux一切皆文件的基本哲学思想.所以我决定从文件目录开始写. 正文: 首先linux文 ...

  5. 零基础Python应该怎样学习呢?(附视频教程)

    Python应该怎样学习呢? 阶段一:适合自己的学习方式 对于零基础的初学者来说,最迷茫的是不知道怎样开始学习?那这里小编建议可以采用视频+书籍的方式进行学习.看视频学习可以让你迅速掌握编程的基础语法 ...

  6. 编译Qualcomm的Hexagon exampls错误

    在下载了Qualcomm的Hexagon SDK 351版本之后,想跑里面的examples,然后参照文档的说,比如在examples/common/sobel3x3_v60目录下面,先执行了SDK根 ...

  7. 使用jdbc将mysql数据库中的内容封装为指定对象的list集合

    使用jdbc将mysql数据库中的内容封装为指定对象的list集合 public List<User> findAll() { private JdbcTemplate template ...

  8. Linux btrfs文件系统

    btrfs,它名字挺多:B-tree fs;Butter fs;Better fs 开源协议是GPL,2007年由Oracle研发 核心特性: 多物理卷支持,btrfs可由多个物理卷组成:支持RAID ...

  9. P1613 跑路【倍增】【最短路】

    题目描述 小A的工作不仅繁琐,更有苛刻的规定,要求小A每天早上在6:00之前到达公司,否则这个月工资清零.可是小A偏偏又有赖床的坏毛病.于是为了保住自己的工资,小A买了一个十分牛B的空间跑路器,每秒钟 ...

  10. 单源最短路 Bellman-Ford算法(有向图)

    // 单源最短路问题 // Bellman-Ford算法 // 复杂度O(V*E) //! 可以判断负圈 #include <cstdio> #include <iostream&g ...