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. Spark集成的包与引入包冲突

    今天在编写Spark应用的时候,想把处理结果输出为JSON字符串,查到Java比较常用的JSON处理包gson,按照其API编写代码后运行程序,总是出现"NoSuchMethodExcept ...

  2. Tomcat 一台机器运行多个Tomcat

    转 https://www.cnblogs.com/andy1234/p/8866588.html 在一台Win10 PC 上面同时开启两个Tomcat系统为例. 1. 硬件环境 2. 到Tomcat ...

  3. 类———用类定义对象———error:C++表达式必须包含类类型

    //原文参考https://blog.csdn.net/lanchunhui/article/details/52503332 你以为你定义了一个类的对象,其实在编译器看来你是声明了一个函数 clas ...

  4. PBOC第八部分和第十一部分关于TYPEA总结(一)——初始化和防冲突(ISO14443-3)

    PBOC第八部分和第十一部分关于TYPEA总结(一) ——初始化和防冲突(ISO14443-3) 第八部分 与应用无关的非接触式规范 ISO14443(1~4) 第十一部分 非接触式IC卡通讯规范 在 ...

  5. PCIe基础篇(二)、协议详解

    一个完整的PCIe协议体系结构包括应用层.事务层(Transaction Layer).数据链路层(Data Link Layer)和物理层(Physical Layer).其中,应用层由用户需要自行 ...

  6. django2.0变动数据库设置外键报错

    1.报错TypeError: __init__() missing 1 required positional argument: 'on_delete' django2.0以后创建数据库外键的时候必 ...

  7. 03.AutoMapper 之反向映射与逆向扁平化(Reverse Mapping and Unflattening)

    https://www.jianshu.com/p/d72400b337e0 AutoMapper现在支持更丰富的反向映射支持. 假设有以下实体: public class Order { publi ...

  8. 网络爬虫之HTTPClient

    HTTPClient官网:http://hc.apache.org/httpcomponents-client-4.5.x/quickstart.html 问题一:明明浏览器请求有数据,可使用HTTP ...

  9. spring服务器接收参数格式

    注:@RequestParam 或@RequestBody等注解是否添加有什么区别 不加:参数可有可无,无参数时为null,但当参数类型是 数字基本类型(int.double)时会报错: 加上@Req ...

  10. 39. Combination Sum (Java)

    Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), fin ...