Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)

题目链接:

Subsequences in Substrings

 Kattis - subsequencesinsubstrings 

题目大意:给你字符串s和t。然后让你在s的所有连续子串中,找出这些连续子串中的非连续子串中包含t的有多少个。

具体思路:我们枚举s的每一个位置,然后判断一下s的包含t的非连续子串中到达那个位置,然后这个字符串两边的长度相乘就是当前位置开始,满足条件的字符位置。然后我们在找从上一次找到首字母位置下一个开始, 继续往下找就可以了。

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 # define ll long long
 4 const int maxn = 4e5+100;
 5 int main()
 6 {
 7     ios::sync_with_stdio(false);
 8     string s,t;
 9     cin>>s>>t;
10     ll len1=s.size();
11     ll len2=t.size();
12     ll ans=0;
13     ll pos=-1;
14     while(1)
15     {
16         int st,ed;
17         st=s.find(t[0],pos+1);
18         if(st==-1)break;
19         ed=st;
20         for(int i=1;i<len2;i++){
21         ed=s.find(t[i],ed+1);
22         if(ed==-1)break;
23         }
24         if(ed==-1)break;
25         ans+=(st-pos)*(len1-ed);
26         pos=st;
27     }
28     printf("%lld\n",ans);
29 }

 

转载于:https://www.cnblogs.com/letlifestop/p/10673207.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值