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. Samba搭建Linux和Windows文件共享服务

    一.Samba简介 Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成.SMB(Server Messages Block,信息服务块)是一种在局域网上共享 ...

  2. 杭电-------2051Bitset(C语言)

    #include<stdio.h> ] = { }; int main() { int m; ; while (~scanf("%d", &m)) { whil ...

  3. C#设计模式学习笔记:(22)备忘录模式

    本笔记摘抄自:https://www.cnblogs.com/PatrickLiu/p/8176974.html,记录一下学习过程以备后续查用. 一.引言 今天我们要讲行为型设计模式的第十个模式--备 ...

  4. java 入门如何设计类

    2019/12/24   |    在校大二上学期    |    太原科技大学 初学java后,我们会发现java难点不在于Java语法难学,而是把我们挂在了如何设计类的“吊绳”上了.这恰恰也是小白 ...

  5. 如何用apply实现一个bind?

    面试题:如何用apply实现一个bind? Function.prototype._bind = function(target) { // 保留调用_bind方法的对象 let _this = th ...

  6. iOS编程实战 — 新的UI范式

    iOS 7给苹果设备带来了全新的用户界面(UI).iOS 7在UI上的变化是自其诞生以来最大的.iOS 7专注于三个重要的特点:清晰.依从和层次.理解这三个特点很重要,因为这有助于设计跟原生的系统内置 ...

  7. mysql设置编码格式--支持中文

    创建table的时候就使用utf8编码 在每次创建表的时候都在最后加上 character set = utf8就可以很好的支持中文 create table xxx ( id int auto_in ...

  8. hadoop3自学入门笔记(1)——虚拟机安装和网络配置

    前言 年过30惶惶不安,又逢疫情,还是不断学习,强化自己的能力.hadoop的视频和书籍在15年的时候就看过,但是一直没动手实践过,要知道技术不经过实战,一点提升也没有.因此下定决心边学边做,希望能有 ...

  9. cf1294E

    题意简述:给一个矩阵,有两种操作可以进行 操作1:改变矩阵中一个元素的值 操作2:将矩阵中某一列的值循环下移 要求用最少的操作次数使得矩阵变成 题解:对于一列来说,我们肯定是先变化然后再循环下移,所以 ...

  10. 区块链 POS和POW的区别

    如果你是一名资深的比特币矿工或商人,你一定听说过POW和POS,否则,很难理解. 读完本文,相信会让你明白,原来,虚拟货币除了挖矿,还有利息! 第一段:通俗的概念解析 POW:全称Proof of W ...