求一个串S有多少子串subS满足s是subS的子序列.len(S)<=100000, len(s)<=100

直接扫一遍...

--------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;
 
typedef long long ll;
 
const int maxn = 109;
 
char S[100009], s[maxn];
int Sn, sn, cnt[maxn], p;
ll ans;
 
int main() {
scanf("%s%s", S, s);
Sn = strlen(S);
sn = strlen(s);
p = 0; ans = 0;
memset(cnt, 0, sizeof cnt);
for(int i = 0; i < Sn; i++) {
for(int j = sn; j-- > 1; )
if(S[i] == s[j]) cnt[j] = max(cnt[j], cnt[j - 1]);
if(s[0] == S[i]) cnt[0] = i + 1;
if(s[sn - 1] == S[i])
ans += (ll) (cnt[sn - 1] - p) * (Sn - i), p = cnt[sn - 1];
}
printf("%lld\n", ans);
return 0;
}

--------------------------------------------------------------------

506. Subsequences Of Substrings

Time limit per test: 0.5 second(s)
Memory limit: 262144 kilobytes
input: standard
output: standard

Andrew has just made a breakthrough in steganography: he realized that one can hide a message in a bigger text by making the message a subsequence of the text. We remind that a strings is called a subsequence of string t if one can remove some (possibly none) letters from t and obtain s. Andrew has prepared a text (represented by a string) with a hidden message (represented by another string which is a subsequence of the first string). But it turns out that he doesn't have enough space to write the text, so he wonders if he can remove some letters from the beginning and/or the end of his text in such a way that the hidden message still stays a subsequence of it. You should find out how many ways are there to remove some (possibly none) letters from the beginning of the given text and some (possibly none) letters from the end of the given text in such a way that the given message is a subsequence of the remaining string. Two ways are distinct if the number of letters removed from the beginning or from the end or both are distinct, even if the resulting string is the same. 

Input

The first line of the input file contains the text — a non-empty string of lowercase English letters, no more than  letters long. The second line of the input file contains the message — a non-empty string of lowercase English letters, no more than 100 letters long. It is guaranteed that the message is a subsequence of the given text. 

Output

Output one integer — the sought number of ways. 

Example(s)
sample input
sample output
abraaadabraa baa 
23 

SGU 506.Subsequences Of Substrings的更多相关文章

  1. Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)

    题目链接: Subsequences in Substrings Kattis - subsequencesinsubstrings 题目大意:给你字符串s和t.然后让你在s的所有连续子串中,找出这些 ...

  2. SGU题目总结

    SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...

  3. SDU暑期集训排位(4)

    SDU暑期集训排位(4) C. Pick Your Team 题意 有 \(n\) 个人,每个人有能力值,A 和 B 轮流选人,A 先选,B 选人按照一种给出的优先级, A 可以随便选.A 想最大化己 ...

  4. [LeetCode] Count Different Palindromic Subsequences 计数不同的回文子序列的个数

    Given a string S, find the number of different non-empty palindromic subsequences in S, and return t ...

  5. Kattis之旅——Divisible Subsequences

    Given a sequence of positive integers, count all contiguous subsequences (sometimes called substring ...

  6. Codeforces Round #506 (Div. 3) 题解

    Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...

  7. [LeetCode] 730. Count Different Palindromic Subsequences 计数不同的回文子序列的个数

    Given a string S, find the number of different non-empty palindromic subsequences in S, and return t ...

  8. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. PIC12F508/505/509/510/506/519/526/527单片机破解芯片解密方法!

    IC芯片解密PIC12F508/505/509/510/506/519/526/527单片机破解 单片机芯片解密型号: PIC12F508解密 | PIC12F505解密 | PIC12F506解密  ...

随机推荐

  1. ShareSDK的简化压缩和使用样例

    share sdk 太大了  于是自己 開始简化,  删除了 ipad 的图片和 framework ,  压缩了 sharesdk 中的 图片,用几k的图片 替换了几个 200多k 的图片 仅仅保留 ...

  2. UIlabel添加背景图片

    做UI的时候我们可能想给某个Label添加一个背景图片,但查看的时候会发现好像只有设置背景颜色的方法,不过我们也可以通过这种方式来解决: UIColor *color = [UIColor color ...

  3. User cannot be resolved to a type

    出现 User cannot be resolved to a type 不知道具体问题出在哪里但是我经过将全路径输入并保存后错误消失 将User选上,然后点击保存就可以了! 最后我发现错误消失了!

  4. SEL数据类型,@selector的用法,以及调用SEL

    1.SEL数据类型 SEL是个指针类型的数据,类似C语言中的函数指针.在OC中,每个对象方法都有其对应着一个SEL变量.当我们调用对象方法时,编译器会将该方法转换成一个SEL的数据,然后去类中寻找该方 ...

  5. 内存管理之二——Cocos2d-x学习历程(六)

    1.工厂方法 工厂方法是程序设计中一个经典的设计模式,指的是基类中只定义创建对象的接口,将实际的实现推迟到子类中. CCObject* factoryMethod() { CCObject* ret ...

  6. JSP基础——关于中文乱码问题

    乱码问题十分烦人,今天在写一个登陆的demo时,表单中需要提交的中文姓名,如下代码 <form action="success.jsp" name="success ...

  7. 获取checkbox 的选中状态的id、checkbox的一些操作

    var id_array=new Array(); $('input[name="id"]:checked').each(function(){ id_array.push($(t ...

  8. 练习-checkbox 全选 ,反选, 单选,以及取值

    1.方法1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w ...

  9. CSS 技术关键字

    CSS 技术关键字 元素 替换元素 非替换元素------替换元素和非替换元素的分类是CSS范畴内的,其它的分类都不属于CSS定义的                替换元素和非替换元素的定义是出于“我 ...

  10. 转:CSS3 Flexbox 布局介绍

    转:CSS3 Flexbox 布局介绍 Flexbox是一个用于页面布局的全新CSS3模块功能.它可以把列表放在同一个方向(从左到右或从上到下排列),并且让这些列表能延伸到占用可用的空间.较为复杂的布 ...