codeforces 1203D1(暴力)

时间:2022-07-28
本文章向大家介绍codeforces 1203D1(暴力),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

题意描述

给定两个字符串s和t,s中包含t的子串,求最大删除的区间的长度,使得t仍是s的子串

思路

由于数据范围很小,所以我们暴力枚举删除字符的左右边界,统计长度即可

AC代码

#include<bits/stdc++.h>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(int x=l;x<u;x++)
#define rrep(x,l,u) for(int x=l;x>=u;x--)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef pair<char,char> PCC;
typedef long long ll;
const int N=55;
const int M=1e6+10;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
string s,t;
void solve(){
    cin>>s>>t;
    int len1=s.size();
    int len2=t.size();
    int ans=0;
    rep(i,0,len1){
        rep(j,0,len1){
            int cur=0;
            rep(k,0,len1){
                if(i<=k && k<=j) continue;
                if(s[k]==t[cur]) cur++;
                if(cur==len2) break;
            }
            if(cur==len2) ans=max(ans,j-i+1);
        }
    }
    cout<<ans<<endl;
}
int main(){
    IOS;
    //int t;cin>>t;
    //while(t--){
        solve();
    //}
    return 0;
}