[CF1303E] Erase Subsequences - dp

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的更多相关文章
- Codeforces 1303E. Erase Subsequences 代码(dp 字符串压缩一维状态优化)
https://codeforces.com/contest/1303/problem/E #include<bits/stdc++.h> using namespace std; ; i ...
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
- HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences ...
- HDU 2227 Find the nondecreasing subsequences(DP)
Problem Description How many nondecreasing subsequences can you find in the sequence S = {s1, s2, s3 ...
- Distinct Subsequences (dp)
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- HDU 2227 Find the nondecreasing subsequences dp思想 + 树状数组
http://acm.hdu.edu.cn/showproblem.php?pid=2227 用dp[i]表示以第i个数为结尾的nondecreasing串有多少个. 那么对于每个a[i] 要去找 & ...
- Codeforces1303E. Erase Subsequences
转换一下题意,就相当于问t能不能和s中2个不相同的子串相同,我们可以将t串拆成2个子串t1,t2,得到状态dp[i][j][k]=0/1,表示s判断到i位,t1判断到j位,t2判断到k位,0/1表示是 ...
- 2021record
2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...
- 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 ...
随机推荐
- 【人类观察所】"当代人"正经历的生活
一."即时满足"的互联网 "轻微烦躁,偶尔自燃,当代生活多数时刻的心情基调." 如果你出生于上个世纪,应该能明白木心的<从前慢>里的 「从前的日色变 ...
- Apache 日志记录相关设置
小编最近在配置Apache 服务器啊 就把遇到的信息给记录下来 Apache 自动生成的日志会给系统带来很大的损耗.关闭日志以后,甚至最高可以提高整体性能近40%(粗略估计) 那么如何关闭日志呢? 可 ...
- qt creator源码全方面分析(2-10-5)
目录 The Plugin Manager, the Object Pool, and Registered Objects 插件管理器 对象池和已注册对象 The Plugin Manager, t ...
- pytorch --Rnn语言模型(LSTM,BiLSTM) -- 《Recurrent neural network based language model》
论文通过实现RNN来完成了文本分类. 论文地址:88888888 模型结构图: 原理自行参考论文,code and comment: # -*- coding: utf-8 -*- # @time : ...
- istio-ServiceMesh解决方案
istio-ServiceMesh解决方案 istio(1):ServiceMesh解决方案-k8s安装istio istio(2):流量管理-基于不同版本访问规则控制 istio(3):流量管理-基 ...
- django的自定义权限
最近在写发布系统,涉及到权限的控制 参考 黄小墨同学的博客实现了 如下 1:定义一张权限控制的表 [root@localhost app01]# tailf -25 models.py class P ...
- Python 实现转堆排序算法原理及时间复杂度(多图解释)
原创文章出自公众号:「码农富哥」,欢迎转载和关注,如转载请注明出处! 堆基本概念 堆排序是一个很重要的排序算法,它是高效率的排序算法,复杂度是O(nlogn),堆排序不仅是面试进场考的重点,而且在很多 ...
- Vue子组件和根组件的关系
代码: <script type="text/javascript"> const Foo = Vue.extend({ template: `<div id=& ...
- .NET CORE(C#) WPF简单菜单MVVM绑定
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. .NET CORE(C#) WPF简单菜单MVVM绑定 阅读导航 本文背景 代码实现 本文参考 ...
- HTML <link> 标签 PC移动网站适配
1.在pc版网页上,添加指向对应移动版网址的特殊链接rel="alternate"标记,这有助于百度发现网站的移动版网页所在的位置: <link rel="cano ...