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)的更多相关文章

  1. D2. Remove the Substring (hard version)(思维 )

    D2. Remove the Substring (hard version) time limit per test 2 seconds memory limit per test 256 mega ...

  2. Codeforces Round #579 (Div. 3) D2. Remove the Substring (hard version) (思维,贪心)

    题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最 ...

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

  4. 双指针(最大删除子串)Codeforces Round #579 (Div. 3)--Remove the Substring (hard version)

    题目链接:https://codeforces.com/contest/1203/problem/D2 题意: 给你S串.T串,问你最长删除多长的子串使得S串里仍然有T的子序列. 思路: 想了好久,先 ...

  5. Codeforces - 1203D2 - Remove the Substring (hard version) - 双指针

    https://codeforces.com/contest/1203/problem/D2 上次学了双指针求两个字符串之间的是否t是s的子序列.但其实这个双指针可以求出的是s的前i个位置中匹配t的最 ...

  6. CF1203D2 Remove the Substring (hard version) 题解

    这题初赛让我白给了6分,于是我决定回来解决一下它. 说实话,看原题题面和看CCF代码真是两种完全不同的感受…… ------------思路分析: 把$s$串删去一部分之后,会把$s$串分成两部分,当 ...

  7. Remove the Substring

    D2. Remove the Substring (hard version) 思路:其实就是贪心吧,先从前往后找,找到 t 可在 s 中存在的最小位置 (pre),再从后往前找,找到 t 可在 s ...

  8. Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 水题

    D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference betwe ...

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

随机推荐

  1. js 自调函数

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. 【监控笔记】【2.4】SQL Server中的 Ring Buffer 诊断各种系统资源压力情况

    SQL Server 操作系统(SQLOS)负责管理特定于SQL Server的操作系统资源. 其中相关的动态管理试图sys.dm_os_ring_buffers将被标识为仅供参考.不提供支持.不保证 ...

  3. MySQL索引,备份和还原

    1.索引  1.索引是占硬盘空间 ,也是按页存放的 . 思考题:一个索引页,(数据页)  占用多少个字节  .SQL Server 8192个字节 2.索引:是一种有效组合数据的方式,为了快速查找指定 ...

  4. ^A '\001' 分隔符

    ^A 分隔符符号\001,使用组合按键“ctrl+V+A”获得

  5. Serilog

    参考 asp.net core使用serilog将日志推送到腾讯云日志服务

  6. Spring基础06——依赖注入的一些细节

    1.字面值 可用字符串表示的值,可以通过<value>元素标签或value属性进行注入.基本数据类型及其封装类,String类等类型都可以采取字面值注入的方式.若字面值包含特殊字符,可以使 ...

  7. Vue this.$nextTick原理

    虽然 Vue.js 通常鼓励开发人员沿着“数据驱动”的方式思考,避免直接接触 DOM,但是有时我们确实要这么做.比如一个新闻滚动的列表项.如果在这里需要操作dom, 应该是等待 Vue 完成更新 DO ...

  8. u-boot-2019.07 移植步骤

    doc/README.kconfig Tips to add/remove boards------------------------- When adding a new board, the f ...

  9. java实现一个简单的计数器

    package com.fengunion.sf; import org.junit.platform.commons.util.StringUtils; import java.util.HashM ...

  10. Python四种实现单例模式的方法

    在这之前,先了解super()和__new__()方法 super()方法: 返回一个父类或兄弟类类型的代理对象,让你能够调用一些从继承过来的方法. 它有两个典型作用: a. 在单继承的类层次结构中, ...