D2. Remove the Substring (hard version)
D2. Remove the Substring (hard version)
给字符串s,t,保证t为s的子序列,求s删掉最长多长的子串,满足t仍为s的子序列
记录t中每个字母在s中出现的最右的位置,
然后从s开头开始跑
遇到和当前t[j]相同的s[i],j++
即使得t中相邻两个字符距离最大化
注意j跑完t了,最后一位应该为s的长度
#include<bits/stdc++.h>
using namespace std;
char s[];
char t[];
int R[];
int main()
{
scanf("%s",s);
scanf("%s",t);
int m=strlen(t);
int n=strlen(s);
int j=m-;
int i=n-;
R[m]=n;
while(s[i]!=t[j])
{
i--;
}
R[j--]=i; while(j>=)
{
i--;
while(s[i]!=t[j])i--;
R[j]=i;
j--;
}
j=;
int ans=;
//for(int i=0;i<=m;i++)cout<<R[i]<<' ';
for(int i=;i<n;i++){
// if(j==m)break;
ans=max(ans,R[j]-i);
//cout<<R[j]<<i<<endl;
if(j<m&&s[i]==t[j])j++; }
cout<<ans<<'\n'; }
D2. Remove the Substring (hard version)的更多相关文章
- D2. Remove the Substring (hard version)(思维 )
D2. Remove the Substring (hard version) time limit per test 2 seconds memory limit per test 256 mega ...
- Codeforces Round #579 (Div. 3) D2. Remove the Substring (hard version) (思维,贪心)
题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最 ...
- CF #579 (Div. 3) D1.Remove the Substring (easy version)
D1.Remove the Substring (easy version) time limit per test2 seconds memory limit per test256 megabyt ...
- 双指针(最大删除子串)Codeforces Round #579 (Div. 3)--Remove the Substring (hard version)
题目链接:https://codeforces.com/contest/1203/problem/D2 题意: 给你S串.T串,问你最长删除多长的子串使得S串里仍然有T的子序列. 思路: 想了好久,先 ...
- Codeforces - 1203D2 - Remove the Substring (hard version) - 双指针
https://codeforces.com/contest/1203/problem/D2 上次学了双指针求两个字符串之间的是否t是s的子序列.但其实这个双指针可以求出的是s的前i个位置中匹配t的最 ...
- CF1203D2 Remove the Substring (hard version) 题解
这题初赛让我白给了6分,于是我决定回来解决一下它. 说实话,看原题题面和看CCF代码真是两种完全不同的感受…… ------------思路分析: 把$s$串删去一部分之后,会把$s$串分成两部分,当 ...
- Remove the Substring
D2. Remove the Substring (hard version) 思路:其实就是贪心吧,先从前往后找,找到 t 可在 s 中存在的最小位置 (pre),再从后往前找,找到 t 可在 s ...
- Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 水题
D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference betwe ...
- Codeforces Round #575 (Div. 3) D1+D2. RGB Substring (easy version) D2. RGB Substring (hard version) (思维,枚举,前缀和)
D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inp ...
随机推荐
- gcc 消除未使用变量的警告
我们写代码的时候经常需要遇到一些情况,参数暂时没用到.但是这个参数必须存在. 例如linux下线程实体函数void *thread_xx(void *arg)如果不处理,gcc编译时就会报" ...
- Centos7 搭建pptp服务器
1.检查是否支持pptp 返回ok即表示支持 modprobe ppp-compress-18 && echo ok 2.安装ppp yum install -y ppp 3.安装pp ...
- 同一台电脑管理多个SSH KEY
同一台电脑关于多个SSH KEY管理 笔者之前为电脑中的homestead虚拟机配置过id_rsa,但现在因为想在github上搭建基于hexo的博客,所以需要配置github的ssh key,因此产 ...
- phpstorm配置成sublime的代码高亮逼格风格
使用sublime text3的风格来编程感觉是相当逼格的,然而在php的时候还是觉得phpstorm用起来更顺手一点. 正好在phpstorm中也有配置sublime类似风格的插件,这里来教大家如何 ...
- 深度学习之depthwise separable convolution,计算量及参数量
目录: 1.什么是depthwise separable convolution? 2.分析计算量.flops 3.参数量 4.与传统卷积比较 5.reference
- 01-Django-urls
# Django系统- 环境 - python3.6 - django1.18- 参考资料 - [django中文教程](http://python.usyiyi.cn/)# 环境搭建- anacon ...
- HTML面试问题收集(1)
1.浏览器页面有哪三层构成,分别是什么,作用是什么? 构成:结构层.表示层.行为层分别是:HTML.CSS.JavaScript 作用:HTML实现页面结构,CSS完成页面的表现与风格,JavaScr ...
- Axiso解决跨域访问
问题: 在项目中需要需要讲本地项目去请求一个URL接口获取数据 例如: 本地请求地址:http://127.0.0.1:19323/site/info.json 请求Url地址:http://www. ...
- SPSS25 下载安装和激活
目录 1. 其他版本 2. 安装步骤 3. 下载地址 1. 其他版本 参考:https://www.cnblogs.com/coco56/p/11648399.html 2. 安装步骤 打开安装包 下 ...
- The Battle of Chibi(数据结构优化dp,树状数组)
The Battle of Chibi Cao Cao made up a big army and was going to invade the whole South China. Yu Zho ...