求一个串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. Intellij Idea的一些配置

    1.字体 修改IDEA面板字体:Settings->Appearance-> Override default fonts by(not recommended)选中,选择自己喜欢的字体 ...

  2. some knowledge

    注意 关于cornerstone无法上传library文件的问题  上面是我要添加的library文件,网上提供的方法是 在CornerStone的菜单栏里面 View->ShowIgnoreI ...

  3. EC读书笔记系列之3:条款5、条款6、条款7

    条款5:了解C++默默编写并调用哪些函数 记住: ★编译器可以(仅仅是可以,并非必须,仅当程序中有这样的用法时才会这么做!!!)暗自为class创建default构造函数,copy构造函数,copy ...

  4. Algorithms 4th - 1.1 Basic Programming Model - EXERCISES

    欢迎交流 1.1.1 a. 7 b. 200.0000002 c. true 1.1.2 a. 1.618 b. 10.0 c. true d. 33 1.1.3 public class MainA ...

  5. Android BaseAdapter

    ListView显示与缓存机制:      只会加载当前屏幕所要显示的数据.显示完成就会被回收到Recycler中.       BaseAdapter 基本结构:      public int g ...

  6. PHP中mktime() 函数对于日期运算和验证

    mktime() 函数对于日期运算和验证非常有用.它可以自动校正越界的输入: // 语法:mktime(hour,minute,second,month,day,year) echo(date('Y- ...

  7. 重写javascript浮点运算

    javascript中变量存储时不区分number和float类型,同一按照float存储; javascript使用IEEE 754-2008标准定义的64bit浮点格式存储number,decim ...

  8. Follow your heart

    世界上最可怕的两个词,一个是执着,一个是认真.认真的人改变自己,执着的人改变命运.任何时候都别怕重来,每个看似低的起点,都是通往高峰的必经之路.不用抱怨那些不尽如人意,问问自己,你够努力了吗?转自人民 ...

  9. STL容器的内存分配

    这篇文章参考的是侯捷的<STL源码剖析>,所以主要介绍的是SGI STL实现版本,这个版本也是g++自带的版本,另外有J.Plauger实现版本对应的是cl自带的版本,他们都是基于HP实现 ...

  10. 让vs2010的html编辑器验证html5语法

    或者在Tools -> option -> Text Editor -> Html -> Validation